vue實(shí)現(xiàn)聯(lián)動(dòng)選擇
本文實(shí)例為大家分享了vue實(shí)現(xiàn)聯(lián)動(dòng)選擇的具體代碼,供大家參考,具體內(nèi)容如下
因?yàn)轫?xiàng)目需求,作者和作者頭像都是由后臺(tái)接口傳給前端的,所以我就選擇用select來(lái)實(shí)現(xiàn)
主要想法就是當(dāng)選擇作者后,自動(dòng)顯示頭像,(效果如下)
下面就分享下代碼(element):
頁(yè)面用的就是form表單
<el-form ref="goodsCircle" :model="goodsCircle" class="form-container"> ? ? ? ? ? ? ? <el-form-item ? ? ? ? ? ? label-width="80px" ? ? ? ? ? ? label="作者:" ? ? ? ? ? ? class="postInfo-container-item" ? ? ? ? ? ? prop="authorInfo" ? ? ? ? ? > ? ? ? ? ? ? <el-select ? ? ? ? ? ? ? filterable ? ? ? ? ? ? ? v-model="goodsCircle.authorInfo" ? ? ? ? ? ? ? remote ? ? ? ? ? ? ? placeholder="搜索用戶" ? ? ? ? ? ? ? @change="getAuthorImg" ? ? ? ? ? ? ? ? ? value-key="key" ? ? ? ? ? ? > ? ? ? ? ? ? ? <el-option ? ? ? ? ? ? ? ? v-for="item in authorArr" ? ? ? ? ? ? ? ? :key="item.key" ? ? ? ? ? ? ? ? :label="item.label" ? ? ? ? ? ? ? ? :value="item" ? ? ? ? ? ? ? /> ? ? ? ? ? ? </el-select> ? ? ? ? ? ? ? ? ? ? </el-form-item> ? ? ? ? ? ? <el-form-item prop="authorImg" label-width="80px" label="頭像" style="margin-bottom: 30px;"> ? ? ? ? <el-image ? ? ? ? ? v-model="goodsCircle.authorImg" ? ? ? ? ? :src="goodsCircle.authorImg" ? ? ? ? ? fit="cover" ? ? ? ? ? lazy ? ? ? ? ? style="width: 200px;height: 180px;" ? ? ? ? > ? ? ? ? ? <div slot="placeholder" class="image-slot"> ? ? ? ? ? ? 加載中 ? ? ? ? ? ? <span class="dot">...</span> ? ? ? ? ? </div> ? ? ? ? </el-image> ? ? ? </el-form-item> ?</el-form>
<script> export default { ? data() { ? ? return { ? ? ? authorArr: [], ? ? ? goodsCircle: { ? ? ? ? authorInfo: {}, ? ? ? ? author: "", ? ? ? ? authorImg: "", ? ?}, ? ? }; ? }, ? methods: { ? ? //查詢發(fā)布者 ? ? getAuthorList() { ? ? ? this.$api.operation ? ? ? ? .getAuthorList({ ? ? ? ? ? status: this.listQuery.authorStatus ? ? ? ? })//這是接口 ? ? ? ? .then(res => { ? ? ? ? ? if (res.data.code == 200) { ? ? ? ? ? ? let arr = []; ? ? ? ? ? ? res.data.result.forEach((res, index) => { ? ? ? ? ? ? ? arr[index] = { ? ? ? ? ? ? ? ? key: res.id, ? ? ? ? ? ? ? ? label: res.author, ? ? ? ? ? ? ? ? authorImg: res.authorImg ? ? ? ? ? ? ? }; ? ? ? ? ? ? }); ? ? ? ? ? ? this.authorArr = arr; ? ? ? ? ? } ? ? ? ? }); ? ? }, ? ? //change事件 ? ? getAuthorImg(param) { ? ? ? this.goodsCircle.authorImg = param.authorImg; ? ? ? this.goodsCircle.author = param.label; ? ? } ? }, ?? ? ? created() { ? ? this.getAuthorList(); ? } }; </script>
這樣就能實(shí)現(xiàn)效果了。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
解決Ant Design Modal內(nèi)嵌Form表單initialValue值不動(dòng)態(tài)更新問(wèn)題
這篇文章主要介紹了解決Ant Design Modal內(nèi)嵌Form表單initialValue值不動(dòng)態(tài)更新問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10vue數(shù)據(jù)變化但頁(yè)面刷新問(wèn)題
這篇文章主要介紹了vue數(shù)據(jù)變化但頁(yè)面刷新問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04vuex刷新頁(yè)面后如何解決丟失store的數(shù)據(jù)問(wèn)題
這篇文章主要介紹了vuex刷新頁(yè)面后如何解決丟失store的數(shù)據(jù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12在vue項(xiàng)目中優(yōu)雅的使用SVG的方法實(shí)例詳解
本文旨在介紹如何在項(xiàng)目中配置和方便的使用svg圖標(biāo)。本文以vue項(xiàng)目為例給大家介紹在vue項(xiàng)目中優(yōu)雅的使用SVG的方法,需要的朋友參考下吧2018-12-12