绑定属性.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <div id="app">
  3. <h2>{{msg}}</h2>
  4. <div v-bind:title="title1">鼠标瞄上去看下效果</div>
  5. <div :title="title1">鼠标瞄上去看下效果</div>
  6. <img v-bind:src="url1" />
  7. <div v-bind:class="css_title">绑定css</div>
  8. <div v-bind:style="{'width':boxWdith+'px'}">测试</div>
  9. <div v-html="html1"></div>
  10. <div v-text="text1">
  11. <button v-on:click="btnRun()">btn1</button>
  12. <button @click="btnRun()">换一种写法</button>
  13. </div>
  14. <div>
  15. <ol>
  16. <li v-for="i in list">{{i}}</li>
  17. </ol>
  18. </div>
  19. <div>
  20. <ol>
  21. <li v-for="(v,k) in obj1">{{k}}:{{v}}</li>
  22. </ol>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'app',
  29. data() {
  30. return {
  31. msg: "hello world!",
  32. title1: "测试",
  33. url1: "https://baidu.com",
  34. text1: "测试text",
  35. html1: "<h2>html1</h2>",
  36. boxWdith: 500,
  37. list: [1, 2, 3, 4, "hello"],
  38. obj1: [{}, {}, {}]
  39. }
  40. },
  41. methods: {
  42. btnRun: function() {
  43. alert("btn被点击了");
  44. this.obj1.push("增加一条数据");
  45. },
  46. }
  47. }
  48. </script>
  49. <style lang="scss">
  50. .css_title {
  51. color: #008000;
  52. }
  53. </style>