Reputation: 573
I have a vuejs component (map.vue
) like this:
<script>
import '../../assets/js/map.js'
export default {
name: 'home',
data () {
return {
init_data: {},
}
},
created: function() {
this.init_data = window.get_init_data(this.view, function(response) {
document.title = response.body.page_title;
init_map(some_arguments);
});
}
}
</script>
map.js:
const key = ******;
function init_map(some_args) {
...
}
Error:
[Vue warn]: Error in created hook: "ReferenceError: init_map is not defined"
And in fact, inspecting the source code the function it's been called before it's signature.
Note: I don't want to include map.js
in webpack entries because i only need this script in one component (map.vue
).
Upvotes: 1
Views: 1008
Reputation: 740
Try this
test.js
export function writeHello() {
console.log('hello');
}
*****.vue
import {writeHello} from './../test.js';
export default {
created() {
writeHello();
}
}
Upvotes: 1