1:创建js文件,写入所需的方法,例如:log.js
function log(text){
console.log(text);
}
module.exports = {
log: log
}
2:页面或组件引入js文件,然后调用,如下:
<script>
import log from '@/js/log.js'
export default {
data() {
return {
}
},
created() {
log.log('page created');
},
methods: {
}
}
</script>
3:打印结果:page created