zoukankan      html  css  js  c++  java
  • 微信小程序点击不同的按钮,展示不同的信息内容

    1.有四个导航:推荐、食品、服装、用品;点击不同的按钮,展示不同的内容

    2.wxml

    <view class='nav'>
      <block wx:for="{{nav}}" wx:key="key">
        <view class="{{ curIndex === item.id ? 'txt' : ''}}" data-id="{{item.id}}" bindtap="navTap">{{item.title}}</view>
      </block>
    </view>
    <scroll-view>
      <block wx:for="{{list}}" wx:key="key">
        <block wx:if="{{curNav == 0 }}">
          <view class='msg'>
            <text class='name'>{{item.name}}</text>
            <text class='price'>{{item.price}}</text>
          </view>
        </block>
        <block wx:elif="{{curNav == item.type }}">
          <view class='msg'>
            <text class='name'>{{item.name}}</text>
            <text class='price'>{{item.price}}</text>
          </view>
        </block>
      </block>
    </scroll-view>
    

    2.wxss

    /* pages/nav/nav.wxss */
    .nav{
      display: flex;
      justify-content: center;
      align-items: center;
      height:150rpx;
    }
    .nav view{
      33.33%;
      text-align: center;
    }
    .txt{
      color:#f00;
    }
    .msg{
      height:150rpx;
      display: flex;
      align-items: center;
      border:1px solid #ddd;
      padding:0 60rpx;
    }
    .msg text{
      display: block;
    }
    .msg .name{
      300rpx;
      margin-right:30rpx;
    }
    

    3.js

    data: {
        nav:[
          {
            title:"推荐",
            id:0
          },
          {
            title: "食物",
            id: 1
          },
          {
            title: "服装",
            id: 2
          },
          {
            title: "用品",
            id: 3
          }
        ],
        list:[
          {
            id:1,
            name:'辣条',
            price:3.5,
            type:1
          },
          {
            id: 2,
            name: '辣条1',
            price: 3.5,
            type: 1
          },
          {
            id: 3,
            name: '男装',
            price: 300,
            type: 3
          },
          {
            id: 4,
            name: '豆腐',
            price: 1,
            type: 1
          },
          {
            id: 5,
            name: '女装',
            price: 150,
            type: 2
          },
          {
            id: 6,
            name: '儿童装',
            price: 80,
            type: 2
          },
          {
            id: 7,
            name: '锅',
            price: 58,
            type: 3
          },
          {
            id: 8,
            name: '床上四件套',
            price: 155,
            type: 3
          },
        ],
        curNav:0,
        curIndex:0
      },
      navTap(e){
        let id = e.currentTarget.dataset.id;
        console.log(id);
        this.setData({
          curNav: id,
          curIndex:id
        })
      },
    

      重点:根据商品的type值来判断展示的内容,如果type值为0,展示所有的商品,如果type的值为1,2,3时,显示相应的商品type的信息

  • 相关阅读:
    用简单C程序分析DOS下的EXE文件【转】
    汇编函数的调用[转自KingofCoders]
    windows下的shellcode剖析浅谈[转自看雪]
    如何写一个简单的病毒程序[转]
    不用注册访问论坛技巧
    函数调用堆栈变化分析[转自看雪]
    IT学生解惑真经(下载)
    Windows 汇编语言编程教程[转]
    ESP定律介绍(转自看雪论坛贴)
    【Anti Virus专题】1.1 病毒的原理 [转自看雪]
  • 原文地址:https://www.cnblogs.com/dyy-dida/p/9635497.html
Copyright © 2011-2022 走看看