vue中點擊切換按鈕功能之點啟用后按鈕變?yōu)榻?/h1>
更新時間:2021年09月14日 11:08:44 作者:大師的修煉之路
這篇文章主要介紹了vue中點擊切換按鈕功能之點啟用后按鈕變?yōu)榻霉δ埽疚耐ㄟ^實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
實現(xiàn)方法分位三步:
- 在template中設置2個按鈕,通過v-if ,v-show來控制;
- data中設置按鈕的默認值;
- methods中控制點擊按鈕切換效果。
<template>
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column
fixed
prop="date"
label="日期"
width="200">
</el-table-column>
<el-table-column
prop="state"
label="狀態(tài)"
width="150">
</el-table-column>
<el-table-column
prop="name"
label="姓名"
width="120">
<template slot-scope="scope">
<el-input placeholder="請輸入內(nèi)容" v-show="scope.row.show" v-model="scope.row.姓名">
</el-input>
<span v-show="!scope.row.show">{{scope.row.姓名}}
</span>
</template>
</el-table-column>
<el-table-column
prop="province"
label="省份"
width="120">
</el-table-column>
<el-table-column
prop="city"
label="市區(qū)"
width="120">
</el-table-column>
<el-table-column
prop="address"
label="地址"
width="300"
:show-overflow-tooltip="true" >
</el-table-column>
<el-table-column
prop="zip"
label="郵編"
width="120">
</el-table-column>
<el-table-column
fixed="right"
label="操作"
width="300">
<template slot-scope="scope">
<el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
<el-button @click="scope.row.show =true" type="text" size="small">編輯</el-button>
<el-button @click="scope.row.show =false" type="text" size="small">保存</el-button>
<el-button @click="changeStatus" type="text" size="small" v-if="btnStatus == 0">啟用</el-button>
<el-button @click="changeStatus" type="text" size="small" v-show="btnStatus == 1">禁用</el-button>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
methods: {
handleClick(row) {
console.log(row);
},
changeStatus(){
this.btnStatus = this.btnStatus === 0 ? 1 : 0;
}
},
data() {
return {
btnStatus: 0,
tableData: [{
date: '2016-05-02',
name: '王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎',
province: '上海',
city: '普陀區(qū)',
address: '上海市普陀區(qū)金沙江路 1518 弄上海市普陀區(qū)金沙江路 1518 弄',
zip: 200333,
show:true
}, {
date: '2016-05-04',
name: '王小虎',
province: '上海',
city: '普陀區(qū)',
address: '上海市普陀區(qū)金沙江路 1517 弄',
zip: 200333,
show:true
}]
}
}
}
</script>
另外,注意下,data中,按鈕的默認值要放在data下,圖1。
不能放在table中,否則會按鈕顯示不出來,且會報錯,圖2:Property or method "btnStatus" is not defined on the instance but referenced during render.
這個報錯原因是:在template里面或者在方法里面使用了 “btnStatus” ,但是在data里面沒有定義。


到此這篇關于vue中點擊切換按鈕功能之點啟用后按鈕變?yōu)榻玫奈恼戮徒榻B到這了,更多相關vue點擊切換按鈕內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
-
vue項目中監(jiān)聽手機物理返回鍵的實現(xiàn)
這篇文章主要介紹了vue項目中監(jiān)聽手機物理返回鍵的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧 2020-01-01
-
使用vue-router切換頁面時,獲取上一頁url以及當前頁面url的方法
這篇文章主要介紹了使用vue-router切換頁面時,獲取上一頁url以及當前頁面url的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
2019-05-05
-
教你在Vue3中使用useStorage輕松實現(xiàn)localStorage功能
這篇文章主要給大家介紹了關于如何在Vue3中使用useStorage輕松實現(xiàn)localStorage功能的相關資料,文中通過實例代碼介紹的非常詳細,對大家的學習或工作具有一定的參考學習價值,需要的朋友可以參考下 2023-06-06
-
element多選表格中使用Switch開關的實現(xiàn)
當在做后臺管理系統(tǒng)的時候,會用到用戶的狀態(tài)管理這個功能,本文主要介紹了element多選表格中使用Switch開關的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧 2023-07-07
-
nuxt 自定義 auth 中間件實現(xiàn)令牌的持久化操作
這篇文章主要介紹了nuxt 自定義 auth 中間件實現(xiàn)令牌的持久化操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧 2020-11-11
-
Vue中的scoped和 elememt-plus的樣式修改方法
Vue中的scoped屬性用于實現(xiàn)樣式隔離,確保組件間的樣式互不影響,通過在組件的style標簽內(nèi)添加任何內(nèi)容,可以為組件生成一個唯一的哈希值,從而實現(xiàn)樣式的定位,本文通過實例代碼講解Vue中的scoped和 elememt-plus的樣式修改方法,感興趣的朋友一起看看吧 2025-01-01
最新評論
實現(xiàn)方法分位三步:
- 在template中設置2個按鈕,通過v-if ,v-show來控制;
- data中設置按鈕的默認值;
- methods中控制點擊按鈕切換效果。
<template>
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column
fixed
prop="date"
label="日期"
width="200">
</el-table-column>
<el-table-column
prop="state"
label="狀態(tài)"
width="150">
</el-table-column>
<el-table-column
prop="name"
label="姓名"
width="120">
<template slot-scope="scope">
<el-input placeholder="請輸入內(nèi)容" v-show="scope.row.show" v-model="scope.row.姓名">
</el-input>
<span v-show="!scope.row.show">{{scope.row.姓名}}
</span>
</template>
</el-table-column>
<el-table-column
prop="province"
label="省份"
width="120">
</el-table-column>
<el-table-column
prop="city"
label="市區(qū)"
width="120">
</el-table-column>
<el-table-column
prop="address"
label="地址"
width="300"
:show-overflow-tooltip="true" >
</el-table-column>
<el-table-column
prop="zip"
label="郵編"
width="120">
</el-table-column>
<el-table-column
fixed="right"
label="操作"
width="300">
<template slot-scope="scope">
<el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
<el-button @click="scope.row.show =true" type="text" size="small">編輯</el-button>
<el-button @click="scope.row.show =false" type="text" size="small">保存</el-button>
<el-button @click="changeStatus" type="text" size="small" v-if="btnStatus == 0">啟用</el-button>
<el-button @click="changeStatus" type="text" size="small" v-show="btnStatus == 1">禁用</el-button>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
methods: {
handleClick(row) {
console.log(row);
},
changeStatus(){
this.btnStatus = this.btnStatus === 0 ? 1 : 0;
}
},
data() {
return {
btnStatus: 0,
tableData: [{
date: '2016-05-02',
name: '王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎',
province: '上海',
city: '普陀區(qū)',
address: '上海市普陀區(qū)金沙江路 1518 弄上海市普陀區(qū)金沙江路 1518 弄',
zip: 200333,
show:true
}, {
date: '2016-05-04',
name: '王小虎',
province: '上海',
city: '普陀區(qū)',
address: '上海市普陀區(qū)金沙江路 1517 弄',
zip: 200333,
show:true
}]
}
}
}
</script>
另外,注意下,data中,按鈕的默認值要放在data下,圖1。
不能放在table中,否則會按鈕顯示不出來,且會報錯,圖2:Property or method "btnStatus" is not defined on the instance but referenced during render.
這個報錯原因是:在template里面或者在方法里面使用了 “btnStatus” ,但是在data里面沒有定義。


到此這篇關于vue中點擊切換按鈕功能之點啟用后按鈕變?yōu)榻玫奈恼戮徒榻B到這了,更多相關vue點擊切換按鈕內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
vue項目中監(jiān)聽手機物理返回鍵的實現(xiàn)
這篇文章主要介紹了vue項目中監(jiān)聽手機物理返回鍵的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-01-01
使用vue-router切換頁面時,獲取上一頁url以及當前頁面url的方法
這篇文章主要介紹了使用vue-router切換頁面時,獲取上一頁url以及當前頁面url的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-05-05
教你在Vue3中使用useStorage輕松實現(xiàn)localStorage功能
這篇文章主要給大家介紹了關于如何在Vue3中使用useStorage輕松實現(xiàn)localStorage功能的相關資料,文中通過實例代碼介紹的非常詳細,對大家的學習或工作具有一定的參考學習價值,需要的朋友可以參考下2023-06-06
element多選表格中使用Switch開關的實現(xiàn)
當在做后臺管理系統(tǒng)的時候,會用到用戶的狀態(tài)管理這個功能,本文主要介紹了element多選表格中使用Switch開關的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-07-07
nuxt 自定義 auth 中間件實現(xiàn)令牌的持久化操作
這篇文章主要介紹了nuxt 自定義 auth 中間件實現(xiàn)令牌的持久化操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
Vue中的scoped和 elememt-plus的樣式修改方法
Vue中的scoped屬性用于實現(xiàn)樣式隔離,確保組件間的樣式互不影響,通過在組件的style標簽內(nèi)添加任何內(nèi)容,可以為組件生成一個唯一的哈希值,從而實現(xiàn)樣式的定位,本文通過實例代碼講解Vue中的scoped和 elememt-plus的樣式修改方法,感興趣的朋友一起看看吧2025-01-01

