Open openks opened 6 years ago
修改后的search组件,使用原样式
<template>
<div class="mint-search">
<div class="mint-searchbar">
<div class="mint-searchbar-inner">
<i class="mintui mintui-search"></i>
<input ref="input"
@click="visible = true"
type="search"
v-model="currentValue"
:placeholder="placeholder"
class="mint-searchbar-core">
</div>
<a class="mint-searchbar-cancel confirm"
@click="handerConfirm"
v-show="visible"
v-text="confirmText">
</a>
<a class="mint-searchbar-cancel"
@click="handerCancel"
v-show="visible"
v-text="cancelText">
</a>
</div>
<div class="mint-search-list"
v-show="show || currentValue">
<div class="mint-search-list-warp">
<slot>
<x-cell v-for="(item, index) in result"
:key="index"
:title="item"></x-cell>
</slot>
</div>
</div>
</div>
</template>
<script>
import XCell from 'mint-ui/packages/cell/index.js';
if (process.env.NODE_ENV === 'component') {
require('mint-ui/packages/cell/style.css');
}
/**
* mt-search
* @module components/search
* @desc 搜索框
* @param {string} value - 绑定值
* @param {string} [cancel-text=取消] - 取消按钮文字
* @param {string} [placeholder=取消] - 搜索框占位内容
* @param {boolean} [autofocus=false] - 自动 focus
* @param {boolean} [show=false] - 始终显示列表
* @param {string[]} [result] - 结果列表
* @param {slot} 结果列表
*
* @example
* <mt-search :value.sync="value" :result.sync="result"></mt-search>
* <mt-search :value.sync="value">
* <mt-cell v-for="item in result" :title="item"></mt-cell>
* </mt-search>
*/
export default {
name: 'mt-search',
data () {
return {
visible: false,
currentValue: this.value
};
},
components: { XCell },
watch: {
currentValue (val) {
this.$emit('input', val);
},
value (val) {
this.currentValue = val;
}
},
props: {
value: String,
autofocus: Boolean,
show: Boolean,
cancelText: {
default: '取消'
},
confirmText: {
default: '查询'
},
placeholder: {
default: '搜索'
},
result: Array
},
methods: {
handerConfirm () {
this.visible = false
this.$emit("confirm", this.currentValue)
},
handerCancel () {
this.visible = false
this.currentValue = ""
this.$emit("cancel")
},
},
mounted () {
this.autofocus && this.$refs.input.focus();
}
};
</script>
在手机端选择很多数据时,做可输必选或者先输入部分数据后点击搜索按钮显示结果 实现方案
点击取消,清空输入框,删除搜索结果,关闭弹层
Q1:如果页面上有很多这样的输入框如何确保数据正确回填
Q2: 能否一个页面同时打开两个可输必选组件 不能
mint-ui的具体实现方案