<template>
<div>
<h1>{{ message }}</h1>
<button @click="increment">Count is: {{ count }}</button>
</div>
</template>
<script setup>
import { ref, reactive } from 'vue';
// 声明一个响应式变量
const message = ref('Hello Vue 3!');
const count = ref(0);
// 定义一个方法来增加计数
const increment = () => {
count.value++;
};
</script>
<style scoped>
button {
font-weight: bold;
}
</style>
模板部分 (<template>):
{{ }} 绑定数据到视图中。@click 指令绑定点击事件到 increment 方法。脚本部分 (<script setup>):
<script setup> 语法糖,这是 Vue 3 的新特性,简化了组件的编写方式。ref 创建响应式变量 message 和 count。increment 方法,当按钮被点击时会调用此方法并增加 count 的值。样式部分 (<style scoped>):
scoped 属性确保样式只作用于当前组件。上一篇:vue跨域访问接口
下一篇:vite+vue
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站