【发布时间】:2021-03-25 07:53:09
【问题描述】:
我正在使用 Vue CLI,我想导入托管在另一台服务器上的 JavaScript 文件。我尝试的所有方法都出现了如下所示的相同错误。
我该如何解决这个问题?如何导入外部 JS 文件?
我的 Vue 文件如下所示。
<!-- Use preprocessors via the lang attribute! e.g. <template lang="pug"> -->
<template>
<div id="app">
<p>Test</p>
<button @click="doSomething">Say hello.</button>
</div>
</template>
<script>
import TestFile from "https://.../src/TestFile.js";
export default {
data() {
return {
message: "<h1>anything</h1>"
}
},
async mounted() {
await TestFile.build();
},
methods: {
doSomething() {
alert(message);
},
},
};
</script>
<!-- Use preprocessors via the lang attribute! e.g. <style lang="scss"> -->
<style>
</style>
【问题讨论】:
标签: javascript vue.js vue-cli