main.js中我寫了幾個不同的語言Vue.use(VueI18n)const messages = {en: {message: {hello: 'world hello'}},zh: {message: {hello: '世界'}},de:{message:{hello:'Die Welt'}},ko:{message:{hello:'??'}}}const i18n = new VueI18n({locale: 'ko',messages})new Vue({i18n ,el: '#app',router,template: '<App/>',components: { App }})在組件中<button type="button" @click="changeLanguage('en')">英文</button><script>export default {data () {return {hello: this.$t('message.hello'),}},methods:{changeLanguage(value){if(value=='en'){this.$locale='en'}}}}</script>我想做個點擊事件實現點擊切換語言,但是沒有思路。我一直想著如何把組件中拿到的locale傳到main.js中去改變語言顯示。思路是否有問題呢,也不知道如何傳過去。。。
添加回答
舉報
0/150
提交
取消