我用nvm管理node版本 使用18.4.0,新建vue3项目:
nvm use 18.4.0
npm create vue@latest
1、选项式API
<script>
export default {
data()return {count:0},
methods:{increment(){this.count++}}
mounted(){console.log(`The initial count is ${this.count}.`)}}
</script>
<template>
<button @click="increment">选项式API:count is:{{ count }}</button></template>
2、组合式API
<script setup>
import { ref, onMounted } from 'vue
const count = ref(0)
function increment(){
count.value++
onMounted(()=>{console.log(`The initial count is ${count.value}.`
</script>
<template>
<button @click="increment">组合式API:Count is: {{ count }}</button></template>
v-bind可以绑定对象