<template>
<div>
<p ref="name">dohee</p>
</div>
</template>
<script>
export default {
// ...
methods: {
getNameNode() {
console.log(this.$refs.name); //<p>dohee</p>
}
}
}
</script>
<template>
<div>
<p ref="name">dohee</p>
</div>
</template>
<script>
import {ref, onMounted} from 'vue';
export default {
// ...
setup() {
//ref명과 동일한 변수명 선언 !
const name = ref();
onMounted(() => {
console.log(name.value); //<p>dohee</p>
});
return { name };
}
}
</script>