I have a components.js file that looks like this:
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
}
}
});
But I'm getting:
Uncaught SyntaxError: Unexpected token {
How do I import a function from another plain JS file and use it within a Vue component?
Thanks.
import {}something from a file if you do not bundle your code. If your app is served from a web-server for example it would not know how to fetch "./tools.js".