為了簡化 Vue 組件的標記,我嘗試使用一個對象作為道具。當按照組件基礎知識的代碼示例中的描述定義組件的模板時,Vue.js一切正常。但是嘗試將模板定義為 x 模板時,我收到一條錯誤消息,無法讀取未定義的屬性“標題”。這是代碼:<div id="app"> <script type="text/x-template" id="post-template"> <div class="blog-post"> <h3>{{ post.title }}</h3> <div v-html="post.content"></div> </div> </script> <blog-post v-for="post in posts" v-bind:key="post.id" v-bind:post="post"></blog-post></div>const data = { posts: [ { title: "Hello World", content: "Bar" } ]};let postComponent = { props: ['post'], template: 'post-template'}const vue = new Vue({ el: '#app', components: { 'blog-post': postComponent }, data() { return data; }});是否無法訪問 a 中的對象屬性,x-template或者我的代碼有問題?
Vue.js 組件:Props 作為對象不適用于 x-template
HUWWW
2023-01-06 09:27:41