赞
踩
父组件向子组件传值用props
例子:
父组件
- 父组件el-from-item包含自定义组件Dctionary
- 父组件:
-
- <el-form-item v-for="item in setParamList" :key="item" :label="item">
- <Dictionary
- v-model="params"
- :dict-key="getDictKey()"
- @input="selectParams($event, item)"
- :manage="item"
- />
- </el-form-item>
-
- #记得引入子组件:import Dictionary from "@/components/Dictionary/index";
- #上面就是将item值放到manage变量中去传递
-
子组件
- 子组件:
-
- <template>
- <el-select
- v-model="dictionary"
- placeholder="请选择"
- clearable
- @change="selectChange"
- size="mini"
- >
- <el-option
- v-for="item in dictionaryOptions"
- :key="item.id"
- :label="item.text"
- :value="item.id"
- />
- </el-select>
- </template>
-
- <script>
- import { getDictList } from "@/api/dict-data"; // 获取数据字典
- export default {
- name: "GetDictionary",
- props:["manage"],
- props: {
- manage:String,
- dictKey: String, // 字典code
- updataDict: String // 回显绑定的值
- },
- }
- #首先写一个props:["manage"] ,这里的参数就是父组件中的变量,然后再props:{manage:String}中定义变量的类型
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。