Vue vs React
属性传递和访问方式
- Vue
- 传递
:name=''访问this.name
- 传递
- React
- 传递
name=访问this.props.name
- 传递
子调父方法
- Vue
- this.$parent.onSave()
- 父
@onSave="onSave"子this.$emit('onSave', param1, param2)
- React
- 父
onSave={this.onSave}子this.props.onSave()
- 父
动态和静态属性
- Vue
:name="'确定'+scope.row.status == 1 ? '禁用': '开启' + '吗?'"
- React
name={`确定${this.state.status==1? '禁用': '开启'}吗?`}
child监听props的变化
由于props传给child的属性
:name在组件的访问方式是this.name类似于data的访问,所以可以直接通过watch监听
// 父
<comp :name="xx"/>
// 子
{
props: {
name: {
type: String,
default: ''
}
},
watch:{
name: function(newV, oldV){}
}
}