vue global function

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')


      }
    }
  }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326530112&siteId=291194637