函数
Vue3的函数直接定义在script标签中,并且可以直接使用
html
<template>
<button @click="showAltert">按钮</button>
</template>
<script setup lang='ts'>
function showAltert(){
alert("Hello Vue3!");
}
</script>注意,在函数中使用的所有变量和函数都不需要使用Vue2的this指针
html
<template>
<div>{{ num }}</div>
<button @click="changeNum">按钮</button>
</template>
<script setup lang='ts'>
import {ref} from "vue";
let text1=ref(0);
function changeNum(){
text1.value+=1;
}
</script>