So I built a Single Page Application in VueJS
which works nicely but the SEO sucks as expected, so I decided to make a normal HTML site with some pages having VueJS
code (Remote hosting so no node else I would go SSR).
I followed this guide which works fin
I have a search.js
which contains my VueJS
instance and methods etc
Vue.component('todo-component', {
template: '#todo-component',
data: function () {
return {
items: [
{
id: 'item-1',
title: 'Checkout vue',
completed: false
}, {
id: 'item-2',
title: 'Use this stuff!!',
completed: false
}
],
newItem: ''
};
},
methods: {
addItem: function () {
if (this.newItem) {
var item = {
id: Math.random(0, 10000),
title: this.newItem,
completed: false
};
this.items.push(item);
this.newItem = '';
}
}
}
});
var app = new Vue({
el: '#vue-app'
});
However, I need to import stuff like axios and other components
if I add an import statement to the script above, it comes up with
import axios from "axios";
Uncaught SyntaxError: Unexpected identifier
Where should my imports go?
2
Answers
Since you are directly writing code running in the browser, you can simply include the
axios
cdn in your html code beforesearch.js
is loaded:As for components import, you can read more about component registration here. Generally if your components are registered globally via
Vue.component('my-component', {})
syntax, you should be able to directly use it within your code.You’re missing
axios
library so add it as follow :i’m also providing you of how to use it when you work with browser :