[英]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.