vue父子传值, 如何用computed接收并操作数据?

父子传值传值, 如何用computed接收并操作数据?

父组件

// 父组件下面的子组件
<Current
      :status="orderID"
/>
data() {
    return {
      orderID: '',
    };
},
methods: {
  // 该事件是从另外一个子组件传值过来的, 接收值之后传给另外一个子组件使用
  getOrderID(orderID) {
    this.orderID = orderID;
  },
},

子组件

props: {
    status: {
      type: String,
      default: String,
    },
},
// computed如何来操作

子组件已经从父组件传值成功
clipboard.png

阅读 7k
3 个回答
<template>
  <div>{{statusText}}</div>
</template>

<script>
export default {
  props: {
    status: {
      type: String,
      default: String
    }
  },
  components: {},
  data () {
    return {}
  },
  computed: {
    statusText () {
      console.log(this.status)
      if (this.status === '1234') {
        return '哈哈哈哈'
      }
    }
  },
  created () {
  },
  methods: {}
}
</script>

computed: { dataGet() { return this.status } }
因为要使用到getter,所以在template里面使用一下
我用过的方法是<div v-model="dataGet" style="display:none"></div>

子组件中已经能够获取statusText数据,建议使用vuex,在getters中处理相关的数据。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题