// MyTemplate.vue
<template>
<div> <!-- keep this single "parent" div in your template -->
<!-- your Blade layout here -->
</div>
</template>
<script>
export default {
props: [ 'data' ]
}
</script>
// app.js
import Vue from 'vue';
window.Vue = Vue;
Vue.component('my-template', require('./MyTemplate.vue').default);
const app = new Vue({
el: '#app'
});
<my-template :data="{{ $onePhpVarThatHoldsAllYourData }}></my-template>
进入Vue模板后,如果@auth
没有Ajax请求,您将无法返回Laravel方法(例如)或获取其他数据,因此请确保将所需的所有数据预先打包在Vue模板中。在这种情况下,您发送的所有数据都将在Vue模板中带有您为其分配的prop名称的前缀data
。
循环(例如@foreach
)到v-for
s:
@foreach ($items as $item)
<li>{{ $item }}</li>
@endforeach
变成
<li v-for="item in data.items">{{ item }}</li>
控制结构(例如@if ($something !== $somethingElse) ... @endif
)到v-if
:
<div v-if="data.something !== data.somethingElse">
...
</div>
非常感谢您提供详细的答案,这将对我的工作有所帮助。