溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么使用Vue實現(xiàn)單個按鈕顯示和隱藏的變換功能

發(fā)布時間:2022-11-11 10:07:39 來源:億速云 閱讀:172 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹了怎么使用Vue實現(xiàn)單個按鈕顯示和隱藏的變換功能的相關(guān)知識,內(nèi)容詳細(xì)易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇怎么使用Vue實現(xiàn)單個按鈕顯示和隱藏的變換功能文章都會有所收獲,下面我們一起來看看吧。

在做后臺管理系統(tǒng)中遇到一個需求, 點擊一個按鈕可以變換里面字的內(nèi)容

當(dāng)狀態(tài)為顯示的時候, 該行第一個按鈕為隱藏;

當(dāng)狀態(tài)為隱藏的時候, 該行第一個按鈕為顯示;

具體代碼如下:

<!-- 數(shù)據(jù)表格 -->
<el-table :data="tableData" class="table" stripe border v-loading="loading">
 <el-table-column type="index" label="序號" width="70"></el-table-column>
 <el-table-column prop="status" label="狀態(tài)"></el-table-column>
 <el-table-column label="操作">
 <template slot-scope="scope">
  <el-button size="mini" type="warning" @click="handleIsDisplay(scope.$index, scope.row)">
   {{scope.row.status=='顯示'?'隱藏':'顯示'}}
  </el-button>
  <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">編輯</el-button>
  <!-- <el-button size="mini" type="danger" @click="handleRemove(scope.$index, scope.row)">刪除</el-button> -->
 </template>
 </el-table-column>
</el-table>

也可以用第二種方法:

<!-- 數(shù)據(jù)表格 -->
<el-table :data="tableData" class="table" stripe border v-loading="loading">
 <el-table-column type="index" label="序號" width="70"></el-table-column>
 <el-table-column prop="status" label="狀態(tài)"></el-table-column>
 <el-table-column label="操作">
 <template slot-scope="scope">
  <el-button v-if="scope.row.status=='顯示'" size="mini" type="warning" 
   @click="handleIsDisplay(scope.$index, scope.row)">隱藏</el-button>
  <el-button v-if="scope.row.status=='隱藏'" size="mini" type="warning" 
   @click="handleIsDisplay(scope.$index, scope.row)">顯示</el-button>
  <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">編輯</el-button>
  <!-- <el-button size="mini" type="danger" @click="handleRemove(scope.$index, scope.row)">刪除</el-button> -->
 </template>
 </el-table-column>
</el-table>

為什么要使用Vue

Vue是一款友好的、多用途且高性能的JavaScript框架,使用vue可以創(chuàng)建可維護性和可測試性更強的代碼庫,Vue允許可以將一個網(wǎng)頁分割成可復(fù)用的組件,每個組件都包含屬于自己的HTML、CSS、JavaScript,以用來渲染網(wǎng)頁中相應(yīng)的地方,所以越來越多的前端開發(fā)者使用vue。

關(guān)于“怎么使用Vue實現(xiàn)單個按鈕顯示和隱藏的變換功能”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“怎么使用Vue實現(xiàn)單個按鈕顯示和隱藏的變換功能”知識都有一定的了解,大家如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

vue
AI