vue el-radio單選傳值和默認(rèn)選中方式
vue el-radio單選傳值和默認(rèn)選中
父組件點(diǎn)擊"關(guān)聯(lián)公司"輸入框 (如下圖) 彈出子組件dialog

子組件效果下圖默認(rèn)選中

父組件代碼
點(diǎn)擊輸入框
<el-form-item v-if="flag" label="關(guān)聯(lián)公司" prop="orgName">
<el-select v-model="form.orgName" clearable placeholder="請(qǐng)選擇公司" @click.native="selectCompany" @clear="clearCompany" />
</el-form-item>引入的子組件
<!-- 添加公司 -->
<Select-company
:company-visible.sync="companyVisible"
:company-name="companyName"
@select-company="companyData"
/>
對(duì)應(yīng)的函數(shù)
// 清空輸入框
clearCompany() {
this.form.orgName = null
},
// 打開(kāi)子組件
selectCompany(row) {
this.companyVisible = true
},
// 選中返回的值
companyData(data) {
this.form.orgName = data.companyName
},
變量
companyVisible: false
companyName: null,
子組件代碼 SelectCompany.vue
<template>
<el-dialog
:title="title"
:visible.sync="_visible"
:close-on-click-modal="false"
:destroy-on-close="true"
width="40%"
@closed="handleClosed"
@open="handleOpend"
>
<!-- 搜索欄 -->
<el-row>
<el-form :inline="true" :model="searchMap">
<el-form-item label="公司名稱:">
<el-input v-model="searchMap.companyName" size="mini" />
</el-form-item>
<div style="float:right">
<el-button
size="mini"
type="primary"
round
icon="el-icon-search"
@click="onSearch"
>搜索</el-button></div>
</el-form>
</el-row>
<!-- 功能區(qū) -->
<el-table ref="sensorTable" :data="tableData" tooltip-effect="dark" height="255" style="width: 100%" @current-change="clickChange">
<el-table-column label="選擇" width="55">
<template slot-scope="scope">
<el-radio v-model="tableRadio" :label="scope.row"><i /></el-radio>
</template>
</el-table-column>
<el-table-column
type="index"
label="序號(hào)"
:index="indexMethod"
align="center"
/>
<el-table-column
prop="companyName"
label="公司名稱"
:show-overflow-tooltip="true"
/>
<el-table-column
prop="repairPhone"
label="報(bào)修電話"
:show-overflow-tooltip="true"
/>
</el-table>
<!-- 分頁(yè)條 -->
<div class="t-paging">
<el-pagination
:current-page="searchMap.pageNum"
:page-sizes="savedPageSizes"
:page-size="savedPageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="handleClosed">取 消</el-button>
<el-button @click="submit">確 定</el-button>
</span>
</el-dialog>
</template>
<script>
import { mapState } from 'vuex'
import { queryTable } from '@/api/dictionary/company.js'
export default {
name: 'CompanySection',
props: {
companyVisible: {
type: Boolean,
default: false
},
companyName: {
type: String,
default: null
}},
data() {
return {
tableData: [],
tableRadio: {
id: null,
companyName: null
},
searchMap: {
companyName: null,
pageNum: 1,
pageSize: null
},
total: 0
}
},
computed: {
...mapState({
savedPageSize: state => state.page.tablePageSize,
savedPageSizes: state => state.page.tablePageSizes,
tableStyle: state => state.page.tableStyle
}),
title: {
get() {
return '公司信息'
}
},
_visible: {
get() {
return this.companyVisible
},
set(val) {
this.$emit('update:companyVisible', val)
}
}
},
created() {
this.initData()
},
methods: {
initData() {
this.searchMap.pageSize = this.savedPageSize
this.loadTable()
},
loadTable() {
queryTable(this.searchMap).then(res => {
this.tableData = res.items
this.total = res.total
this.tableRadio = res.items.find(e => e.companyName === this.companyName)
})
},
indexMethod(index) {
index = (index + 1) + (this.searchMap.pageNum - 1) * this.searchMap.pageSize
return index
},
handleOpend() {
this.loadTable()
},
handleClosed() {
this.tableRadio = null
this.searchMap.pageNum = 1
this.searchMap.companyName = null
this._visible = false
},
clickChange(item) {
this.tableRadio = item
},
submit() {
if (this.tableRadio == null) {
this.$message({
type: 'warning',
message: '請(qǐng)選擇一條數(shù)據(jù)!'
})
} else {
this.$emit('select-company', this.tableRadio)
this._visible = false
}
},
// 搜索按鈕
onSearch() {
this.loadTable()
},
handleSizeChange(val) {
console.log(`每頁(yè) ${val} 條`)
this.searchMap.pageSize = val
this.$store.dispatch('setTablePageSize', val)
this.loadTable()
}, handleCurrentChange(val) {
console.log(`當(dāng)前頁(yè): ${val}`)
this.searchMap.pageNum = val
this.loadTable()
}
}
}
</script>
<style scoped></style>總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue $refs動(dòng)態(tài)拼接獲取值問(wèn)題
這篇文章主要介紹了vue $refs動(dòng)態(tài)拼接獲取值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
vue3全局組件自動(dòng)注冊(cè)功能實(shí)現(xiàn)
本文主要講述vue3的全局公共組件的自動(dòng)注冊(cè)功能,本文分步驟結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-02-02
vue+elementUI中el-radio設(shè)置默認(rèn)值方式
這篇文章主要介紹了vue+elementUI中el-radio設(shè)置默認(rèn)值方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12
Vue屏幕自適應(yīng)三種實(shí)現(xiàn)方法詳解
在實(shí)際業(yè)務(wù)中,我們常用圖表來(lái)做數(shù)據(jù)統(tǒng)計(jì),數(shù)據(jù)展示,數(shù)據(jù)可視化等比較直觀的方式來(lái)達(dá)到一目了然的數(shù)據(jù)查看,但在大屏開(kāi)發(fā)過(guò)程中,常會(huì)因?yàn)檫m配不同屏幕而感到困擾,下面我們來(lái)解決一下這個(gè)不算難題的難題2022-11-11
Vue實(shí)現(xiàn)點(diǎn)擊按鈕進(jìn)行上下頁(yè)切換
這篇文章主要介紹了Vue實(shí)現(xiàn)點(diǎn)擊按鈕進(jìn)行上下頁(yè)的切換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
Vue替代vuex的存儲(chǔ)庫(kù)Pinia詳細(xì)介紹
這篇文章主要介紹了Vue替代vuex的存儲(chǔ)庫(kù)Pinia,聽(tīng)說(shuō)pinia與vue3更配,便開(kāi)啟了vue3的學(xué)習(xí)之路,pinia 和 vuex 具有相同的功效, 是 Vue 的存儲(chǔ)庫(kù),它允許您跨組件/頁(yè)面共享狀態(tài)2022-09-09
Vue使用vue-draggable 插件在不同列表之間拖拽功能
這篇文章主要介紹了使用vue-draggable 插件在不同列表之間拖拽,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
Vue中實(shí)現(xiàn)動(dòng)態(tài)更新JSON數(shù)據(jù)的三種方式
在 Vue 項(xiàng)目中動(dòng)態(tài)更新 JSON 數(shù)據(jù),可以通過(guò)以下幾種方式實(shí)現(xiàn),具體方法取決于你的需求,比如數(shù)據(jù)是存儲(chǔ)在前端還是后端、是否需要持久化等,文中通過(guò)代碼示例講解的非常詳細(xì),需要的朋友可以參考下2025-04-04

