v-指令的用法.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <script src="http://static.runoob.com/assets/vue/1.0.11/vue.min.js"></script>
  9. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  10. </head>
  11. <body>
  12. <div id="root">
  13. <h1 v-text="name+'!'">hello {{name}}</h1>
  14. <h2 v-text="age[1]+'!'"></h2>
  15. <h3 v-html="content"></h3>
  16. <!-- @click点击事件, @keyup点击键盘回车事件 -->
  17. <input type="button" value="v-on指令" v-on:click="doIt(2)">
  18. <input type="button" value="v-on简写" @click="doIt(5)">
  19. <input type="button" value="双击事件" @dblclick="doIt(6)">
  20. <input type="button" value="键盘" @keyup.enter="doIt(18)">
  21. <h3 @click="changeFood">{{food}}</h3>
  22. <h4 v-show="ifshow">demo1</h4>
  23. <h4 v-show="true">demo2</h4>
  24. <h4 v-show="false">demo3</h4>
  25. <h4 v-if="true">demo10</h4>
  26. <h4 v-if="false">demo11</h4>
  27. <!-- v-bind 指令的使用-->
  28. </div>
  29. <div id="bind">
  30. <img v-bind:src="imgSrc" alt="">
  31. <img :src="imgSrc" alt="">
  32. </div>
  33. <div id="vue_for">
  34. <li v-for="(index,item) in school">
  35. {{index}} : {{item}}
  36. </li>
  37. </div>
  38. <!-- v-model数据双向绑定 -->
  39. <input type="button" value="get请求" id="get">
  40. <input type="button" value="post请求" id="post">
  41. <script type="text/javascript">
  42. document.querySelector("#get").onclick = function(){
  43. axios.get("").then(function(response){
  44. console.log(response);
  45. },function (err){
  46. })
  47. }
  48. const vue = new Vue({
  49. el:'#root',
  50. data:{
  51. name:'zhangsan',
  52. school:{
  53. class:'163',
  54. grade:'123'
  55. },
  56. age:['12','15'],
  57. content: "<a href='www.baidu.com'>百度</a>",
  58. food: "橘子",
  59. ifshow: true
  60. },
  61. methods: {
  62. doIt:function(a){
  63. alert(a);
  64. },
  65. changeFood:function(){
  66. this.food+="香蕉";
  67. this.ifshow=false;
  68. }
  69. }
  70. });
  71. const vue_bind = new Vue({
  72. el:"#bind",
  73. data:{
  74. imgSrc:"http://www.itheima.com/images/logo.png"
  75. },
  76. methods:{
  77. }
  78. })
  79. const vue_for=new Vue({
  80. el:"#vue_for",
  81. data:{
  82. school:["a","b","c","d"]
  83. },
  84. methods:{
  85. }
  86. })
  87. </script>
  88. </body>
  89. </html>