数据/组件绑定的各种情况

在这里插入图片描述

<template>
  <div class="wrapper">
    <!-- 数据绑定 -->
    <text class="title">数据绑定:{{ title }}</text>

    <!-- 事件绑定 -->
    <text @click="press" class="bt">事件绑定:{{ click }}</text>

    <!-- 列表渲染 -->
    <div>
      <!-- tid="uniqueId"表示使用数组list的数组元素$item.uniqueId作为数组元素的唯一 Id,且必须保证 uniqueId 这个属性值在每个数组元素都不一样。 -->
      <div for="{{list}}" tid="uniqueId">
        <!-- <text>{{$idx}}</text> -->
        <text>列表渲染{{ $item.uniqueId }}</text>
      </div>
    </div>

    <!-- 条件渲染 if-->
    <div>
      <text if="{{display}}">Hello-1</text>
      <text elif="{{display}}">Hello-2</text>
      <text else>条件渲染 if else</text>
    </div>
    <!-- 条件渲染 show-->
    <text show="{{visible}}">条件渲染 show</text>
    <!-- 逻辑控制块 -->
    <div>
      <list class="ljk">
        <text>逻辑块控制:</text>
        <block for="cities">
          <list-item type="city">
            <text  style="color:#faf8fc">{{ $item.name }}</text>
          </list-item>
          <list-item type="spot" for="$item.spots">
            <text>{{ $item.address }}</text>
          </list-item>
        </block>
      </list>
    </div>
    <!-- 引入自定义组件 -->
    <div>
    
    </div>
    <!-- 动态组件 -->
    <div>
    
    </div>
    <!-- 过滤组件 -->
    <div>
      <text>{{ message | capitalize('11','22','33') }}</text>
    </div>

  </div>
</template>

<script>
export default {
  data: {
    title: "欢迎体验快应用",
    click:'123456',
    list: [
      {
        uniqueId: 1
      },
      {
        uniqueId: 2
      },
      {
        uniqueId: 3
      },
      {
        uniqueId: 4
      }
    ],
    display: false,
    visible: true,
    cities: [
        {
          name: '北京',
          spots: [
            {
              address: '北京市朝阳区'
            }
          ]
        },
        {
          name: '上海',
          spots: [
            {
              address: '上海迪士尼乐园'
            },
            {
              address: '上海博物馆'
            },
            {
              address: '上海琉璃艺术博物馆'
            },
            {
              address: '南京路步行街'
            }
          ]
        }
    ],
    message: '过滤组件',
  },
  
  capitalize(value) {
      if (!value) return ''
      value = value.toString()
      return value.charAt(0).toUpperCase() + value.slice(1)
    },
  props: [],
  
  onInit() {},
  press(e) {
      this.click = 'Hello'
    }
}
</script>

<style>
.wrapper {
  flex-direction: column;
}
.bt{
  width: 100px;
  height: 100px;
  color: #0000ff;
}
.ljk{
  background-color: #cccccc;
  height: 160px;
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

礼礼。

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值