版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Thekingyu/article/details/80713354
新建一个js
export function activeFn(yong) {
// 中英文互换
let storage=localStorage.getItem("key")
if(storage=="zhCHS"){
this.ch=false
this.eng=true
this.$i18n.locale='zhCHS'
}else {
this.$i18n.locale='en'
this.eng=false
this.ch=true
}
yong(11) 每个页面调用这个方法
}
页面调用
import {activeFn} from "../../../unit";
methods:{
activeFn,
}
每次页面加载调用yong()
mounted(){
this.activeFn(yong);
}
如果打包出现问题如
ERROR in .xxx.js from UglifyJs Unexpected token:
有人说这是es6不支持。选择babel-loader没有。我认为是单纯的安装路径找不到,解决方法
在build里的webpack.base.conf.js里找到下面的一行代码添加你的路径 例如:
扫描二维码关注公众号,回复:
4600837 查看本文章
{ test: /\.js$/, loader: 'babel-loader', include: [resolve('src'), resolve('test'),resolve('unit/index')] },
就行了