setup
修改了之前 export default 的写法<template>
<h1>{{ msg }}</h1>
</template>
<script setup>
const msg = 'hello'
</script>
<template>
<h1>{{ msg }}</h1>
</template>
<script setup>
import { ref } from 'vue'
const msg = ref('hello')
</script>
// Hello.vue
<template>
<h1>{{ props.msg }}</h1>
</template>
<script setup>
import { defineProps } from 'vue'
const props = defineProps({
msg: String
})
</script>
<template>
<Hello :msg="msg"></Hello>
</template>
<script setup>
import { ref } from 'vue'
import Hello from './Hello.vue'
const msg = ref('vue3')
</script>
<template>
<div>
<h1>这是一段红色的文字</h1>
<button @click="color = 'green'"> 点击改变文字颜色</button>
</div>
</template>
<script setup>
import {ref} from 'vue'
const color = ref('red')
</script>
<style>
h1 {
color: v-bind(color)
}
</style>
因篇幅问题不能全部显示,请点此查看更多更全内容