| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <script src="./js/vue.js"></script>
- </head>
- <body>
- <div id="app">
- <h1>{{message}}</h1>
- <button @click="changeMessage">改变消息</button>
- </div>
- <script>
- new Vue({
- el: '#app',
- data: {
- message:""
- },
- methods:{
- changeMessage(){
- this.message="Hello Vue!"
- },
- // 自定义函数一定要写在methods中
- loadPage(){
- console.log("页面已经加载")
- }
- },
- // 生命周期函数
- // beforeCreate 表示:准备创建Vue实例之前 执行
- beforeCreate(){
- console.log("beforeCreate")
- },
- // 创建Vue实例成功以后执行 但是页面内容还没有展示
- // 常用于页面刷新时候的数据获取
- created(){
- console.log("created")
- },
- // 在整个DOM挂载之前 把整个DOM解构整理好了 还没有渲染到页面中
- beforeMount(){
- console.log("beforeMount")
- },
- // 在整个DOM挂载完成后执行 页面内容已经渲染到了页面中
- // 常用于修改页面样式或者内容
- mounted(){
- console.log("mounted")
- // 调用方法加载页面
- // 调用自定义函数使用this.函数名称()
- this.loadPage()
- },
- // data中的值发生变化的时候触发
- // 在数据更新之前执行
- beforeUpdate(){
- console.log("beforeUpdate")
- },
- // 在数据更新完成后执行
- updated(){
- console.log("updated");
- },
- // 在Vue实例销毁之前执行 (一般为跳转页面之前)
- beforeDistroy(){
- console.log("beforeDistroy")
- },
- // 在Vue实例销毁完成后执行
- destroyed(){
- console.log("destroyed")
- }
- })
- </script>
- </body>
- </html>
|