在使用Laravel框架开发软件并需要使用Vue库的情况下,您将面临一些障碍,包括如何访问Laravel提供的文件翻译系统。比如如何访问trans('home.var')
发布于 2020-05-23 04:49:58
1:在刀片中正常传递trans prop,只需要使用json_encode()方法使用json进行编码:
<component :trans="{{json_encode(trans('home'))}}"></component>
2:在vue组件页面中,需要先对json数据进行解码,并将翻译数据设置为一些var:
export default {
props:['trans'],
data () {
return {
translation:[],
};
},
created(){
this.setTranslation()
},
methods:{
setTranslation(){
let decoded_trans = JSON.parse(this.trans);
this.transaction = decoded_trans;
}
}
3:现在你可以访问laravel trans了,但要小心,因为vue不会检测到你是调用了last node还是first。
<template>
<div>
<h2>{{translation.header.login}}</h2> // this line in laravel mean : trans('home.header.login')
</div>
<template>
最后,我最近开始学习vue,所以这种方法可能有一些缺陷,但我们都努力从中受益:)
发布于 2021-10-11 07:12:23
像这样添加语言文件
<messagings v-bind:language="{{ json_encode(trans('messages')) }}"></messagings>
然后在vue组件中像这样打印
<h4>{{ this.language.messaging }}</h4>
https://stackoverflow.com/questions/61963654
复制相似问题