vue 如何解构对象作为 props 传递?

* parent.vue

<template>
  <div>
    <CHild :config="config"></CHild>
  </div>
</template>

<script>
export default {
  data() {
    return {
      config: {
        type: "component",
        label: "组件",
        value: 0
      }
    };
  }
};
</script>
  • child.vue
<template>
  <div>type:{{ type }} label:{{ label }} value:{{ value }}</div>
</template>

<script>
export default {
  props: {
    type: String,
    label: String,
    value: Number
  }
};
</script>

我想在parent.vue 传递 config 的时候就把它解构,child 接受对应的普通类型值.
求教大佬怎么操作?

阅读 4.1k
1 个回答

试试<CHild v-bind="config"></CHild>

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