当前位置:首页 > 前端

vue踩坑记20201027

Z先生5年前 (2020-10-27)前端970

elemeui/antd等框架,再使用复选框、下拉选择框时,如果通过v-model绑定了值,那么选择时,界面不会改变。

方法一:使用default-value指定默认值,@change去改变本该v-model的值,但是这样表单验证无法使用,而且如果一个界面上有多个相同元素,则无法联动

<template>
    <div>
        <a-select placeholder="请选择分类" @change="catChange" default-value="data.catid">
            <a-select-option v-for="item in cats" :key="item.catid">
                {{ item.name }}
            </a-select-option>
        </a-select>
    </div>
</template>
<script>
.......
methods: {
    catChange(catid) {
      this.data.catid = catid
    },
}
</script>

方法二:@change时,强制重新渲染 ,完美解决

<template>
    <div>
        <a-select placeholder="请选择分类" @change="forceUpdate" v-model="keepingInfo.catid">
            <a-select-option v-for="item in cats" :key="item.catid">
                {{ item.name }}
            </a-select-option>
        </a-select>
    </div>
</template>
<script>
.......
methods: {
    forceUpdate() {
      this.$forceUpdate()
    },
}
</script>


标签: vueantdelemeui
分享给朋友:

相关文章

vue深度监听

还是不废话,直接上干货watch: { data: { handler: (newVal, oldVal) => { console.log(‘data’, newVal); }, deep:…

js关于this的小技巧

这段时间,vue写的多了,习惯了es6的方式写函数,但是这种写法很容易导致this失效,比如刚刚发布的vue深度监听的问题,用了es6的写法,this就没法用,换回传统写法就可以了。// es6写法,…

【原创】Promise循环执行,以及延时循环

演示代码//核心代码 function promiseMain(page) { return new Promise(function(resolve,&…

问题: - did you register the component correctly......

问题: - did you register the component correctly......

问题:无法使用tree组件提示 Unknown custom element:<a-tree> - did you register the component correctly? Fo…

elemeui表格中点击修改最优雅的方式

需求表格中,某一列需要点击修改。并且能拦截回车事件。 解决方案vue代码 {{ row.order }} JS methods 方法```…

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。