const
list
=
ref
(
[
{
id
:
1
,
title
:
'第一条数据'
}
,
{
id
:
2
,
title
:
'第二条数据'
}
,
{
id
:
3
,
title
:
'第三条数据'
}
,
{
id
:
4
,
title
:
'第四条数据'
}
,
{
id
:
5
,
title
:
'第五条数据'
}
]
)
;
function
getRowId
(
id
)
{
console
.
log
(
'当前被点击的id: '
+
id
)
;
return
{
list
,
getRowId
</
script
>
<
style
scoped
>
.item
{
height
:
30px
;
line-height
:
30px
;
text-align
:
center
;
cursor
:
pointer
;
</
style
>
如果本篇文章对你有帮助的话,很高兴能够帮助上你。
当然,如果你觉得文章有什么让你觉得不合理、或者有更简单的实现方法又或者有理解不来的地方,希望你在看到之后能够在评论里指出来,我会在看到之后尽快的回复你。
在
vue
2里我们可以给
元素
绑定ref属性,然后使用this.$refs.xxx 就可以
获取
到
元素
。
而在
vue
3
版本中,你可以继续使用
vue
2的option Api的语法,也可以使用
vue
2的写法。
或者还是用ref绑定
元素
,然后再setup方法中return 这个ref变量,如下:
<div ref="myDom"> </div>
<script lang="ts">
setup(){
let myDom = ref(null)
<ul class="picBox">
<li v
-
for
="(item,index) in picArr" ><img :src="item.src"@click="selectImg(index)" ref="imgBox" /></li>
<template>
<div v
-
for
="(item, i) in programmeList" :key="item" class="special
-
l
-
one">
class="special
-
l
-
one
-
name"
:ref="
(el) => {
if (el) specialNameArray[i] = el;
前两天有个朋友问我
vue
3
中怎么
获取
table
中的
数据
,我原本教他想用
vue
2
中的
ref的,结果发现
3
和2不同了,研究了半天发现不会用。
无奈就先给了个其他的解决方案,代码如下:
<template>
<div class="test">
<table>
<tr v
-
for
="(item,i) in table_data.td">
<td >{{item}}</td>
<td><butt