<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> hello Vue.js </title> </head> <body> <!--View--> <div id="app"> <button @click="increment"> count值:{{state.count}} </button> </div> <!--引入Vue.js--> <script src="https://unpkg.com/vue@next"></script> <script> const App={ setup(){ //为目标对象创建一个响应式对象 const state = Vue.reactive({count: 0}); function increment(){ state.count++; } return { state, increment } } }; //创建应用程序实例,该实例提供应用程序上下文 //应用程序实例装载的整个组件树将共享相同的上下文 const app = Vue.createApp(App); app.mount(‘#app‘); </script> </body> </html>
原文:https://www.cnblogs.com/mingforyou/p/15140616.html