vue create demo
<template>
<div>{{count}}</div>
<a-button type="primary" @click="add" class="btn">加</a-button>
<a-button type="primary" @click="sub" class="btn">减</a-button>
</template>
<script>
import {ref} from "vue";
export default {
name:"Counter",
setup(){
let count = ref(0);
const add = () => {
count.value++;
}
const sub = () => {
count.value--;
}
return {
count,
add,
sub
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.btn{
margin-right: 10px;
}
</style>
<template>
<Counter></Counter>
</template>
<script>
import Counter from './components/Counter.vue';
export default {
name: 'App',
components: {
Counter
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
import { createApp } from 'vue'
import App from './App.vue';
import Antd from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
createApp(App).use(Antd).mount('#app')
- 测试验证
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210616164722302.gif#pic_center)