[英]Create global method vue on app.js laravel
我想创建使用Laravel-JS-Localization翻译消息的全局方法
但是当我使用 vue mustache 调用该方法时,出现如下错误:
Property or method "trans" is not defined on the instance but referenced during render.
Make sure that this property is reactive.
这是我的 laravel app.js
代码:
require('./bootstrap');
window.Vue = require('vue');
Vue.component('dashboard', require('./components/Dashboard').default);
const app = new Vue({
el: '#vue',
methods: {
trans: function (key) {
return Lang.get(key);
},
},
});
Dashboard.vue
代码:
<template>
<p>{{ trans('common.welcome') }}</p>
</template>
<script>
data () {
return {
name: '',
}
},
</script>
dashboard.blade.php
代码:
..........
<div class="col-9" id="vue">
<dashboard></dashboard>
</div> <!--c end col-8 -->
..........
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.