我正在研究 laravel + spark + vuejs。我正在尝试制作新模块,以下是代码。
路线/web.php
Route::get('/emergency-template-plan', 'EmergencyPlanTemplateController@emergencyTemplatePlan');
Vue js:资源/资产/js/app.js
require('spark-bootstrap');
require('./components/bootstrap');
Vue.component('spark-emergency', {
data() {
return {
all_emergencies:[]
};
},
created() {
this.getEmergencies();
},
methods: {
getEmergencies() {
this.$http.get('/emergency-template-plan')
.then(response => {
this.all_emergencies = response.data;
});
}
}
});
var app = new Vue({
mixins: [require('spark')]
});
控制器: app/Http/Controllers/EmergencyPlanTemplateController.php
public function emergencyTemplatePlan(){
$data = EmergencyPlanTemplate::all();
return view('spark::emergency-template-plan', ['emergencies'=>$data]);
}
查看:resources/views/vendor/spark/emergency-template-plan.blade.php
@extends('spark::layouts.app')
@section('content')
<spark-emergency :all_emergencies="all_emergencies" inline-template>
<tr v-for="emergency in all_emergencies">
<td>
<div class="btn-table-align">
@{{ emergency.type }}
</div>
</td>
</tr>
</spark-emergency>
@endsection
我收到以下错误
Vue warn]:属性或方法“all_emergencies”未在实例上定义,但在渲染期间被引用。确保在 data 选项中声明反应数据属性(在根实例中找到)