見出し画像

【Laravel 7.x / Vue.js】Warning: Use of undefined constant works – assumed ‘’ って出た時

var app = new Vue({
   el: '#app',
   data() {
       return {
           customer_id: '{{ $report->customer_id }}',
           user_id: '<?php echo Auth::user()->id ?>',
           result: '{{ $report->result }}',
           other: '{{ $report->other }}',
           after: '{{ $report-after }}'
       }
   },
})

LaravelとVue.jsを使ってpostする機能を実装中に上記のエラーがconsoleを見ると起こっていました。初見のエラーだったのでかなり焦りましたが、他の方の解決方法を見てると"'" が抜けていたり、記述ミスが多かったので、自分のコードを改めて確認してみると、

var app = new Vue({
   el: '#app',
   data() {
       return {
           customer_id: '{{ $report->customer_id }}',
           user_id: '<?php echo Auth::user()->id ?>',
           result: '{{ $report->result }}',
           other: '{{ $report->other }}',
           after: '{{ $report-after }}' // ここが原因
       }
   },
})

よく見るとafterの(->)が抜けてる。

これを修正して解決。

参考記事
https://cotodama.co/wp-warning/

この記事が気に入ったらサポートをしてみませんか?