尝试将翻译键值的json从laravel刀片传递到vue.js时出现问题 [英] Issue while trying to pass json of translation key-value from laravel blade to vue.js

查看:88
本文介绍了尝试将翻译键值的json从laravel刀片传递到vue.js时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的翻译文件

return [
    "Key1" =>  "Message 1",
    "Key2" => "Message 2",
    "Key3" => "Message 3",
    "Key4" => "Message 4",
    "Key5" => "Message 5",
    "Key6" => "Message 6",
    "Key7" => "Message 7",
    "Key8" => "Message 8",
];

这是Laravel Blade中的代码

<profile
    v-bind:ErrorMessages= "{                            
    Messages: '{!! json_encode(Lang::get('Profile')) !!}'
}">                                
</profile>

在上述组件中,我试图将完整的翻译文件从laravel刀片传递到Vue.js

In the above component, I am trying to pass the complete translation file from laravel blade to Vue.js

但是,以上代码打印了网页中的所有键,并干扰了整个布局.

But, the above code print all keys in the web page and disturbs the whole layout.

我丢失了将laravel从laravel传递到Vue.js的正确格式的信息吗

Am I missing anything to pass the json in correct format from laravel to Vue.js

我可以使用以下代码将对象从laravel传递到vue.js.但是下面更像是手动工作,一个一个地键入文件的每个翻译键.

I am able to pass the object from laravel to vue.js using below code. But below is more like manual work typing each translation key of a file one by one.

<profile
    v-bind:messages= "{                            
    Key1: '{!! trans('Profile.Key1') !!}',
    Key2: '{!! trans('Profile.Key2') !!}',
    Key3: '{!! trans('Profile.Key3') !!}',
    Key4: '{!! trans('Profile.Key4') !!}',
    Key5: '{!! trans('Profile.Key5') !!}',
    Key6: '{!! trans('Profile.Key6') !!}',
    Key7: '{!! trans('Profile.Key7') !!}',
    Key8: '{!! trans('Profile.Key8') !!}'
}">                                
</profile>

推荐答案

尝试一下:

<profile
    v-bind:ErrorMessages= "'{!! json_encode(Lang::get('Profile')) !!}'">                                
</profile>

请注意在"{之间的其他'-这样您就可以将想要的内容作为字符串传递.

Note about additional ' between " and { - so you'll pass what you want as string.

这篇关于尝试将翻译键值的json从laravel刀片传递到vue.js时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆