在wepy创建的项目中,pages目录添加文件text.wpy:
<style lang="less">
.child {
border-bottom: 1px solid #eee;
}
</style>
<template>
<view>
<titlecomp :title="normalVal"></titlecomp>
</view>
</template>
<script>
import wepy from 'wepy'
import Title from '@/components/title'
export default class Index extends wepy.page {
data = {
normalVal: '123',
iterator: [
{
id: '0',
title: '0000'
},
{
id: '1',
title: '0001'
}
]
}
components = {
titlecomp: Title
}
onLoad () {
console.log('text.wpy:', this.normalVal);
// 输出: text.wpy: 123
}
}
</script>
在components添加文件:
title.wpy
<style lang="less">
</style>
<template>
<title_two :title="title"></title_two>
</template>
<script>
import wepy from 'wepy'
import Title2 from './title2'
export default class Title extends wepy.component {
props = {
title:{
type: String
}
}
components = {
title_two: Title2
}
onLoad () {
this.title += 'xxx';
this.$apply();
console.log('title.wpy : ',this.title) // 输出 title.wpy : 123xxx
}
}
</script>
title2.wpy
<style lang="less">
</style>
<template>
<view>{{title}}</view>
</template>
<script>
import wepy from 'wepy'
export default class Title2 extends wepy.component {
props = {
title:{
type: String
}
}
onLoad () {
console.log('title2.wpy:',this.title); // 输出 title2.wpy: 123
}
}
</script>
问题:title2.wpy 没有得到预期的 123xxx
即可。。。。