鍍金池/ 問答/HTML/ v-for 怎么實現(xiàn)怎么實現(xiàn)對某個指定元素的文本節(jié)點的獲取呢?

v-for 怎么實現(xiàn)怎么實現(xiàn)對某個指定元素的文本節(jié)點的獲取呢?

通過v-for生成列表,每行中的tr都有復(fù)制按鈕,點擊復(fù)制實現(xiàn)對tr中的某個td文本節(jié)點copy,現(xiàn)在是不知道怎么獲取到item.code文本節(jié)點,這個具體代碼如下:

<tr v-for="(item,index) in userListLimit" :key="index">

            <td>{{item.inserted_at}}</td>
            <td ref="itemCode">{{item.code}}</td>
            <td>{{item.inviter}}</td>
            <td>{{item.invitee}}</td>
            <td>{{item.when_long}}</td>
            <td :title="item.note">{{item.note}}</td>
            <td>
                <a v-if= "item.invitee==''?true:false" @click="myCopy($event)">復(fù)制</a>
            </td>

</tr>
// 點擊復(fù)制到剪貼板

  myCopy(event) {
   // event.target.parentNode.previousSibling.select()
    document.execCommand('Copy')
  },
回答
編輯回答
裸橙

我大概會這樣子做

<td :class="'cls_'+item.code">....</td>
<td><a @click="myCopy(item.code)">復(fù)制</td>
myCopy(code){
//document.getElementByClassName('cls_'+code)
}

復(fù)制文本的話可參考:https://www.cnblogs.com/wisew...

2017年12月7日 15:32
編輯回答
卟乖

直接把code作為參數(shù),myCopy里面修改
myCopy($event),event有用到嗎,沒用的話myCopy(item.code),有用的話myCopy($event,item.code);

然后在tr上綁定ref,這樣通過vue的ref就能找到節(jié)點啦。
<tr v-for="(item,index) in userListLimit" :key="index" :ref='item.code'>

2018年9月9日 11:38