首先,在assets文件夹下,新建js文件夹,创建common.js
export default {
istest(){
console.log("this is test")
}
}
如果是全局(多页面)使用:
1.在main.js中引入
/* 引入公共js*/
import common from '@/assets/js/common.js'
Vue.prototype.common=common;
2.在vue中使用
this.common.istest(); //this is test
如果是单页面使用:
1.在vue的script中引入
import common from '@/assets/js/common'
2.在vue中使用
common.istest(); //this is test