鍍金池/ 問答/HTML/ vue 再封裝的組件如何便捷傳遞props?

vue 再封裝的組件如何便捷傳遞props?

例如el-select 有很多props: value, disabled, filterable, name....

我要封裝這個el-select, 要怎么做才能直接傳遞prop給這個el-select

// my-select.vue

<template>
  <el-select></el-select>
</template>
<script>
export default {
  name: 'my-select'
  props: {
   // 我要怎么做才能傳參給這個el-select
   // 難道我要把它每個參數(shù)都寫一遍?
  }

}
</script>
回答
編輯回答
任她鬧

https://cn.vuejs.org/v2/api/#...

<!-- 通過 $props 將父組件的 props 一起傳給子組件 -->
<child-component v-bind="$props"></child-component>
2018年1月4日 23:14
編輯回答
柚稚

這樣寫

<template>
  <el-select v-bind="$props"></el-select>
</template>
<script>
import { Select } from 'element-ui'
export default {
  name: 'my-select'
  props: {
    ...Select.props, // 這里繼承內(nèi)在組件的props
    myProps: String,
  }

}
</script>

參考文章 - Vue.js實用技巧(二)

2017年9月21日 11:05