2👍
Being modular is never the wrong approach.
Use es6 modules
and a transpiler
such as webpack
, typescript
, etc.
helper.js
export function getLocation() {alert("Hello");}
main.js
import {getLocation} from './helper.js'
Once you start using a transpiler, you should also consider using Vue single file components
. Furthermore, by leveraging vue-cli-3
, you can eliminate much of the heavy boilerplate for the transpiler configuration, testing, and building.
0👍
I created a helper folder, but it was not necessary
helper/getLocation.js
export default function getLocation() {
alert("Hello")
}
App.vue
<template>
<div id="app">
</div>
</template>
<script>
import getLocation from './helper/getLocation.js'
export default {
name: 'App',
data() {
return {}
},
mounted() {
getLocation()
}
}
</script>
Source:stackexchange.com