vue 全局函数
程序员文章站
2022-06-22 17:09:03
...
1. common.js 公用方法
export default { install (Vue, options) { Vue.prototype.fetchI18nText = function (locale) { this.$http.get('http://localhost:8081/static/i18n/' + locale + '.json').then((response) => { Vue.prototype.$i18nText = response.data }) } } }
2. main.js 引用
import common from './common.js' Vue.use(common)
3. any.vue 调用方法
export default { <script> export default { name: 'hello',methods: {changeLocale () { this.fetchI18nText('zh_CN') } } } }