代码如下:

  1. <template>
  2. <view>
  3. <view>
  4. 数据绑定的学习
  5. </view>
  6. <view>
  7. {{msg}}——world!
  8. </view>
  9. <view>{{1+1}}</view>
  10. <view>{{flag ? '我是真的':'我是假的'}}</view>
  11. <image v-bind:src="imgUrl"></image>
  12. v-bind可以缩写的
  13. <image :src='imgUrl'></image>
  14. <view v-for="(item,index) in arr" :key="item.id">
  15. 序号:{{index+1}},名字:{{item.name}},年龄:{{item.age}}
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. msg:'hello',
  24. flag:false,
  25. imgUrl:'http://destiny001.gitee.io/image/monkey_02.jpg',
  26. arr:[
  27. {
  28. name:'宋小宝',
  29. age:20,
  30. id:1
  31. },
  32. {
  33. name:'刘能',
  34. age:21,
  35. id:2
  36. },
  37. {
  38. name:'赵四',
  39. age:22,
  40. id:3
  41. },
  42. {
  43. name:'小沈阳',
  44. age:23,
  45. id:4
  46. },
  47. ]
  48. }
  49. },
  50. methods: {
  51. }
  52. }
  53. </script>
  54. <style>
  55. </style>

v-bind动态绑定属性

在data中定义了一张图片,我们希望把这张图片渲染到页面上

export default{
    data(){
    return{
      img:'http://destiny001.gitee.io/image/monkey_02.jpg'
                    }
                }
}

利用v-bind进行渲染
<image v-bind:src="img"></image>
还可以缩写成:
<image :src='img'></image>

v-for的使用

data中定义一个数组,最终将数组渲染到页面上

data(){
return{
    arr:[
            {name:'刘能',age:29},
            {name:'赵四',age:28}    
]
}
}

利用v-for进行循环:
<view v-for="(item,i) in arr" :key='i'>名字:{{item.name}}---年龄:{{item.age}}</view>
image.png