1. common.js public methods
export default { install (Vue, options) { Vue.prototype.fetchI18nText = function (locale) { this.$http.get('http://localhost:8081/static/i18n/' + locale + '.json').then((response) => { View. prototype . $i18nText = response. data }) } } }
2. main.js reference
import common from './common.js' Vue.use(common)
3. any.vue call method
export default { <script> export default { name: 'hello',methods: {changeLocale () { this.fetchI18nText('zh_CN') } } } }