Vue学习(一)——实现计数器自增

📑前言

本文主要是【Vue】——Vue实现的文章,如果有什么需要改进的地方还请大佬指出⛺️

🎬作者简介:大家好,我是听风与他🥇
☁️博客首页:CSDN主页听风与他
🌄每日一句:狠狠沉淀,顶峰相见

目录

    • 📑前言
    • Vue实现计数器自增
      • 运行结果:
    • 📑文章末尾

Vue实现计数器自增

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><!--引入vue的cdn--><script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body><!--给div增添一个id,方便vue组件进行绑定--><div style="text-align: center;" id="Application"><h1>{{count}}</h1><button v-on:click="clickButton">单击</button></div><script>// 定义一个vue组件,名为App const App = {// 定义组件中的数据data(){return{//目前只用到count数据count:0}},//定义组件中的方法methods:{// 实现单击按钮的方法clickButton(){this.count = this.count + 1}}}// 将vue组件绑定到页面上id为Application的元素上Vue.createApp(App).mount("#Application")</script>
</body>
</html>

运行结果:

在这里插入图片描述

📑文章末尾

在这里插入图片描述