Laravel blade和Vue.js,在模板中连接php函数和Vue.js javascript变量
我想知道如何将laravel php函数lang与javascript变量连接起来。 这里有一个例子: 此代码不起作用。变量文本位于javascript上,并且是动态的。php函数lang不翻译连接的单词display reportParameter.txt\u date 非工作显示reportParameter.txt\u日期Laravel blade和Vue.js,在模板中连接php函数和Vue.js javascript变量,javascript,php,laravel,vue.js,Javascript,Php,Laravel,Vue.js,我想知道如何将laravel php函数lang与javascript变量连接起来。 这里有一个例子: 此代码不起作用。变量文本位于javascript上,并且是动态的。php函数lang不翻译连接的单词display reportParameter.txt\u date 非工作显示reportParameter.txt\u日期 template: ` <div class="text-center mt-1"> <div class="custom-control c
template: `
<div class="text-center mt-1">
<div class="custom-control custom-radio custom-control-inline" v-for="(text, val, index) in optionsParsed">
<input class="custom-control-input" type="radio" v-model="checked" :id="nomRadio+'_'+index" :name="nomRadio" :value="val" @change="getChecked(checked)">
<label class="custom-control-label" :for="nomRadio+'_'+index">@lang('reportParameter.'.@{{text}}')</label>
</div>
</div>
template: `
<div class="text-center mt-1">
<div class="custom-control custom-radio custom-control-inline" v-for="(text, val, index) in optionsParsed">
<input class="custom-control-input" type="radio" v-model="checked" :id="nomRadio+'_'+index" :name="nomRadio" :value="val" @change="getChecked(checked)">
<label class="custom-control-label" :for="nomRadio+'_'+index">@lang('reportParameter.text_date')</label>
</div>
</div>`
模板:`
@lang('reportParameter'.@{{text}}})
`
它在显示日期起作用
template: `
<div class="text-center mt-1">
<div class="custom-control custom-radio custom-control-inline" v-for="(text, val, index) in optionsParsed">
<input class="custom-control-input" type="radio" v-model="checked" :id="nomRadio+'_'+index" :name="nomRadio" :value="val" @change="getChecked(checked)">
<label class="custom-control-label" :for="nomRadio+'_'+index">@lang('reportParameter.'.@{{text}}')</label>
</div>
</div>
template: `
<div class="text-center mt-1">
<div class="custom-control custom-radio custom-control-inline" v-for="(text, val, index) in optionsParsed">
<input class="custom-control-input" type="radio" v-model="checked" :id="nomRadio+'_'+index" :name="nomRadio" :value="val" @change="getChecked(checked)">
<label class="custom-control-label" :for="nomRadio+'_'+index">@lang('reportParameter.text_date')</label>
</div>
</div>`
模板:`
@lang('reportParameter.text\u date')
`
问题是变量文本必须动态生成。问题只是我如何进行连接。我没有正确地连接到那里。我尝试了很多不同的方法,但没有成功
非常感谢您的帮助。您只需在HTML标记中添加一个占位符,如下所示:
<template>
<p>Hallo my name is {{ name }}</p>
</template>
你好,我的名字是{{name}
然后,如果您想从服务器动态获取名称,只需发布一个获取名称的请求
例如,您可以使用axios来实现这一点
<script>
export default {
data: () => ({
name: ''
}),
// going to run if the app gets mounted / page reload so to say
mounted() {
getName();
},
methods: {
getName() {
axios.get('/api/name')
.then(response => name = response.data)
.catch(error => console.log(error)
}
}
}
</script>
导出默认值{
数据:()=>({
名称:“”
}),
//如果安装了应用程序/重新加载页面,那么将运行
安装的(){
getName();
},
方法:{
getName(){
get('/api/name')
.then(response=>name=响应.data)
.catch(错误=>console.log(错误)
}
}
}
让前端(vuejs)调用后端(laravel)并获取您需要的数据。谢谢您的回复。但我想我可以做一些更简单的事情。我已经有了来自数据库的数据。我只想知道如何连接以放入laravel的lang函数中。该函数包含如下字符串:@lang('myTextToTranslate');