美文网首页前端是万能的
这次又是什么原因导致 iview 下拉框点击不灵敏?

这次又是什么原因导致 iview 下拉框点击不灵敏?

作者: 肆意木 | 来源:发表于2019-09-26 10:41 被阅读0次

iview 官网示例代码:

<template>
    <Select v-model="model1" style="width:200px">
        <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>
    </Select>
</template>
<script>
    export default {
        data () {
            return {
                cityList: [
                    {
                        value: 'New York',
                        label: 'New York'
                    },
                    {
                        value: 'London',
                        label: 'London'
                    },
                    {
                        value: 'Sydney',
                        label: 'Sydney'
                    },
                    {
                        value: 'Ottawa',
                        label: 'Ottawa'
                    },
                    {
                        value: 'Paris',
                        label: 'Paris'
                    },
                    {
                        value: 'Canberra',
                        label: 'Canberra'
                    }
                ],
                model1: ''
            }
        }
    }
</script>

记录在实际应用中,我遇到的问题

1. 代码如下(选择城市列表,给后台传入 value 值查询对应城市信息,但是如果传入的是空,返回所有城市信息,结果是空的时候,点击 select 会有一拍显示空白,最后解决方案是 value 修改为 0,调用接口的时候判断是 0 就传入空):

<template>
    <Select v-model="model1" style="width:200px">
        <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>
    </Select>
</template>
<script>
    export default {
        data () {
            return {
                cityList: [
                    {
                        value: '',                     //这里改为 value:'0'
                        label: 'all'
                    },
                    {
                        value: '1',
                        label: 'A'
                    },
                    {
                        value: '2',
                        label: 'B'
                    },
                    {
                        value: '3',
                        label: 'C'
                    }],
                model1: ''
            }
        }
    }
</script>

2. 优化代码时,把 {{}} 里面的文字改成了 v-text,结果导致点击的 select 时候,需要点击两次才可以选中,改回去就解决了这个问题。

<template>
    <Select v-model="model1" style="width:200px">
        <Option v-for="item in cityList" :value="item.value" :key="item.value" v-text=' item.label '></Option>
    </Select>
</template>
<script>
    export default {
        data () {
            return {
                cityList: [
                    {
                        value: '0',                 
                        label: 'all'
                    },
                    {
                        value: '1',
                        label: 'A'
                    },
                    {
                        value: '2',
                        label: 'B'
                    },
                    {
                        value: '3',
                        label: 'C'
                    }],
                model1: ''
            }
        }
    }
</script>

相关文章

网友评论

    本文标题:这次又是什么原因导致 iview 下拉框点击不灵敏?

    本文链接:https://www.haomeiwen.com/subject/cxksyctx.html