<div id="app">
<post-list></post-list>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({});
app.component('PostList', {
data() {
return {
title: 'Java无难事'
}
},
components: {
PostItem: {
props: ['postTitle'],
template: '<h3>{{ postTitle }}</h3>'
}
},
template: '<div><PostItem postTitle="title"></PostItem></div>'
})
app.mount('#app');
</script>
没有响应式的。
返回title,list的数据是java无难事,没有传到item中。item的数据还是title,我猜得对吗?
差不多对。
list的是data
title: “java无难事”
item的是,props
postTitle: “title”
有响应式的。
list的是data
title: “java无难事”
item的是,props
postTitle: “java无难事”,不是title
<div id="app">
<post-list></post-list>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({});
app.component('PostList', {
data() {
return {
title: 'Java无难事'
}
},
components: {
PostItem: {
props: ['postTitle'],
template: '<h3>{{ postTitle }}</h3>'
}
},
template: '<div><PostItem :postTitle="title"></PostItem></div>'
})
app.mount('#app');
</script>