我有一个components.js文件,看起来像这样:
import { lookCoordinate } from './tools.js'; // I get: SyntaxError: Unexpected token {
Vue.component('coordform', {
template: `<form id="popup-box" @submit.prevent="process" v-if="visible"><input type="text" autofocus refs="coordinput" v-model="coords"></input></form>`,
data() {
{
return { coords: '', visible: false }
}
},
created() {
window.addEventListener('keydown', this.toggle)
},
destroyed() {
window.removeEventListener('keydown', this.toggle)
},
methods: {
toggle(e) {
if (e.key == 'g') {
if (this.visible) {
this.visible = false;
} else
this.visible = true;
}
},
process() {
lookCoordinate(this.coords) // Tried to import from tools.js
}
}
});
但我得到: Uncaught SyntaxError: Unexpected token {
如何从另一个普通JS文件导入函数并在Vue组件中使用它?
谢谢。
如果您使用以下命令添加脚本,则支持该功能type="module"
:
<script type="module" src="main.js"></script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句