v-once的用法
1、v-once:主要是在代码中设定后,在网页中使得改变css样式也不会改变之前的属性(仅凭自己理解),使得响应式并不管用!
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>v-once的用法</title> <script src="../js/vue.js"></script> </head> <body> <div id="app"> <h2>{{message}}</h2> </div> <script> const app=new Vue({ el:'#app', data:{ message:'羽生结弦可真帅!' } }); </script> </body> </html>
2、使用v-once 用法之前,避免了之前的响应式的实现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>v-once的用法</title> <script src="../js/vue.js"></script> </head> <body> <div id="app"> <h2>{{message}}</h2> <h2 v-once>{{message}}</h2> </div> <script> const app=new Vue({ el:'#app', data:{ message:'羽生结弦可真帅!' } }); </script> </body> </html>
运行结果显示:

哈哈!这样就可以避免修改css样式使得原属性改变了!

浙公网安备 33010602011771号