vue 封裝自定義組件之tabal列表編輯單元格組件實(shí)例代碼
vue 封裝自定義組件
tabal列表編輯單元格組件
<template>
<div class="editable-cell">
<div class="editable-cell-input-wrapper" v-if='editable'>
<el-input class="editInput" v-model="cellValue" placeholder="請輸入內(nèi)容" v-loading="editLoading" size="small"></el-input>
<el-button type="text"><i class="el-icon-check" @click='check'></i></el-button>
</div>
<div class="editable-cell-text-wrapper" v-else>
{{cellValue || ' '}}
<el-button type="text"><i class="el-icon-edit" @click='edit'></i></el-button>
</div>
</div>
</template>
<script>
import util from '../../common/js/util';
import $ from 'jquery';
import axios from './../../common/ajax/axios.js';
export default {
data() {
return {
cellValue:this.value,
editable:false,
editLoading:false,
};
},
props : [
'value'
],
methods: {
check(){
const self = this;
function callback(){
self.editLoading = false;
self.editable=false;
}
this.editLoading = true;
self.$emit('cellChange',self.cellValue,callback)
},
edit(){
this.editable = true;
}
}
};
</script>
<style lang="less" scoped>
.taskDetail{
margin-left: 10px;
margin-top:10px;
}
.editInput{
width: 200px;
height: 30px;
}
.el-icon-edit{
margin-left: 20px;
}
.el-icon-check{
margin-left: 20px;
}
</style>
<style>
.editInput .el-loading-spinner .circular{
width:20px;
}
</style>

解釋一下:
props:父組件傳遞給子組件的值;
$emit(‘方法名',數(shù)據(jù)) 返回父級數(shù)據(jù),會觸發(fā)父組件中調(diào)用子組件的方法;
父組件中的使用方法:

1.先將組件import 進(jìn)來;
2.然后將組件暴露出去,這樣父組件就可以用了;

總結(jié)
以上所述是小編給大家介紹的vue 封裝自定義組件tabal列表編輯單元格組件,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
vue.js中v-on:textInput無法執(zhí)行事件問題的解決過程
大家都知道vue.js通過v-on完成事件處理與綁定,但最近使用v-on的時(shí)候遇到了一個(gè)問題,所以下面這篇文章主要給大家介紹了關(guān)于vue.js中v-on:textInput無法執(zhí)行事件問題的解決過程,需要的朋友可以參考下。2017-07-07
vue截圖轉(zhuǎn)base64轉(zhuǎn)文件File異步獲取方式
這篇文章主要介紹了vue截圖轉(zhuǎn)base64轉(zhuǎn)文件File異步獲取方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
vue2更改data里的變量不生效時(shí),深層更改data里的變量問題
這篇文章主要介紹了vue2更改data里的變量不生效時(shí),深層更改data里的變量問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
vue解決刷新頁面時(shí)會出現(xiàn)變量閃爍的問題
這篇文章主要介紹了vue解決刷新頁面時(shí)會出現(xiàn)變量閃爍的問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-01-01

