组件内部如何传递数据,
无所谓哪个是父组件,哪个是子组件?一说,就是组件内部传数据
<div id="app">
<post-item post-title="Java 无难事">
</post-item>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({});
app.component('PostItem', {
props: ['postTitle'],
template: `
<h3>{{ postTitle }}</h3>
`
});
app.mount('#app');
</script>
现在就是想给post-item组件赋予Java无难事的标题。
为啥这个运行出来的是,正常吗
<div id="app">
<post-list></post-list>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({});
const PostItem = {
props: ['postTitle'],
template: `<h3> {{ postTitle }}</h3>`
};
app.component('PostList', {
components: {
PostItem
},
template: `<div><PostItem postTitle="Java 无难事“ /></div>`
});
app.mount('#app')
</script>
标点符号太重要了
<div id="app">
<post-list></post-list>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({});
const PostItem = {
props: ['postTitle'],
template: `<h3> {{ postTitle }}</h3>`
};
app.component('PostList', {
components: {
PostItem
},
template: `<div><PostItem postTitle="Java 无难事" /></div>`
});
app.mount('#app')
</script>