I have routes block in HTML Script tag
const routes = [
{path: '/foo', component: Foo},
{path: '/bar', component: Bar}
];
How can I import content of Foo.vue file stored as a separate file?
Foo.vue
<template>
<div>
foo
</div>
</template>
I have tried different ways like script id="foo" src="js/foo.vue" or direct import in block, but none of them worked.
Is there way with Vue.js to import content of external vue file?
Index.html:
<script id="foo" src="js/foo.vue"></script>
<script>
Vue.use(VueMaterial.default);
// const Foo = {template: '<div>foo</div>'};
const Bar = {template: '<div>bar</div>'};
const routes = [
{path: '/foo', component: Vue.component('foo')},
{path: '/bar', component: Bar}
];
const router = new VueRouter({
routes
});
new Vue({
name: "Normal",
router
}).$mount("#app");
</script>
.vue
files (or Single File Components) need to be compiled into plain JavaScript in order to work in the browser. For that you need a build system (usually webpack), check: For Users New to Module Build Systems | Single File Components — Vue.js – yuriy636