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
},
// 打開子組件
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中使用elementui實(shí)現(xiàn)樹組件tree右鍵增刪改功能
這篇文章主要介紹了vue中使用elementui實(shí)現(xiàn)對(duì)樹組件tree右鍵增刪改功能,右擊節(jié)點(diǎn)可進(jìn)行增刪改,對(duì)節(jié)點(diǎn)數(shù)據(jù)進(jìn)行模糊查詢功能,本文給大家分享了完整代碼,需要的朋友可以參考下2022-08-08
基于vue.js路由參數(shù)的實(shí)例講解——簡(jiǎn)單易懂
下面小編就為大家?guī)?lái)一篇基于vue.js路由參數(shù)的實(shí)例講解——簡(jiǎn)單易懂。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09
vue無(wú)法加載文件C:\xx\AppData\Roaming\npm\vue.ps1系統(tǒng)禁止運(yùn)行腳本
這篇文章主要介紹了vue?:?無(wú)法加載文件?C:\xx\AppData\Roaming\npm\vue.ps1...系統(tǒng)上禁止運(yùn)行腳本問(wèn)題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07
vue實(shí)現(xiàn)三級(jí)頁(yè)面跳轉(zhuǎn)功能
這篇文章主要介紹了vue實(shí)現(xiàn)三級(jí)頁(yè)面跳轉(zhuǎn)功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-05-05
vue實(shí)現(xiàn)原理this.$message實(shí)例詳解
這篇文章主要介紹了vue實(shí)現(xiàn)原理this.$message實(shí)例詳解,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-03-03
Vue 清除Form表單校驗(yàn)信息的解決方法(清除表單驗(yàn)證上次提示信息)
這篇文章主要介紹了Vue 清除Form表單校驗(yàn)信息的解決方法(清除表單驗(yàn)證上次提示信息),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04
vue使用html2canvas和jspdf將html轉(zhuǎn)成pdf
在前端開發(fā)中, html轉(zhuǎn)pdf是最常見(jiàn)的需求,下面這篇文章主要給大家介紹了關(guān)于vue如何使用html2canvas和jspdf將html轉(zhuǎn)成pdf的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-03-03
Electron+Vue3+Vite搭建桌面應(yīng)用的示例代碼
本文主要介紹了Electron+Vue3+Vite搭建桌面應(yīng)用的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07

