Vue专题

163 阅读1分钟

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){}
  }
}