第一种 :不采用语法糖以及不考虑响应式数据
-
- <h2>姓名:{{name}}h2>
- <h2>年龄:{{age}}h2>
- <button @click="say">点击button>
-
- <script>
- export default {
- name: "App",
- //不采用语法糖,且不考虑响应式数据
- setup(){
- // 数据
- let name = "张三"
- let age = 20
-
- // 方法
- function say(){
- alert(`你好${name},年龄${age}`)
- }
- return {
- name,age,say
- }
- }
- };
- script>
-
- <style scoped>
- .logo {
- height: 6em;
- padding: 1.5em;
- will-change: filter;
- }
- .logo:hover {
- filter: drop-shadow(0 0 2em #646cffaa);
- }
- .logo.vue:hover {
- filter: drop-shadow(0 0 2em #42b883aa);
- }
- style>
第二种 : 采用语法糖写法以及响应式数据(基本数据类型)
- <div>
- <a href="https://vitejs.dev" target="_blank">
- <img src="/vite.svg" class="logo" alt="Vite logo" />
- a>
- <a href="https://vuejs.org/" target="_blank">
- <img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
- a>
- div>
- <h3>{{a}}h3>
- <button @click="add">+button>
-
- <script setup> //setup语法糖
- import {ref} from 'vue'
- let a = ref(1)
- const add = () =>{
- a.value++
- console.log(a);
- }
- // This starter template is using Vue 3