把值传给组件,然后在组件上循环数据
返回的数据展示:
"data" : [ {
"typeDevice" : [ {
“column_form”:“2”,//下拉框
"column_name" : "单选框",
"value_id" : 55,
}, {
“column_form”:“2”,//下拉框
"column_name" : "列表框",
"column_select" : " 下拉1;下拉2;下拉3",
"value_id" : 51,
}, {
“column_form”:“2”,//下拉框
"column_name" : "第二个列表框",
"column_select" : "值1;值2;值3",
"value_id" : 52,
}
...省略
} ]
}
父页面展示的u-select
<view class="line" v-for="(items,indexs) in item.vals">
<view class="li-name">{{items.column_name}}</view>
<!-- 下拉框 -->
<view class="li-price" v-else-if="items.column_form==2">
<!--通过prop先把值传递到pick(u-select封成的组件里)-->
<byqpick :key="items" :data='items'></byqpick>
</view>
</view>
u-select子组件
<template>
<view class="leave_cont">
<view class="content-list" style="height: 35px; line-height: 35px;">
<view class="posit-input flex-start" @click="show = true">
<label style="padding-left: 11px;" @tap="getLightType">{{ result }}</label>
<u-select :default-value="defaultValue" :mode="mode" v-model="show" :list="list" @confirm="confirm"
@cancel="cancel">
</u-select>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
show: false,
result: '尚未选择',
keya: '',
defaultValue: [0], //默认选项
mode: 'single-column', // single-column, mutil-column, mutil-column-auto
list: [],
};
},
props: ['data'],
created() {
let _this = this;
console.log(_this._props)
let props = {
..._this._props
};
let values = props.data.column_select.split(";");
console.log(values);
for (var i = 0; i < values.length; i++) {
var obj = {
label: values[i],
value: values[i]
};
this.list.push(obj);
}
},
methods: {
confirm(e) {},
cancel(e) {}
}
}
</script>