zoukankan      html  css  js  c++  java
  • 微信小程序 mpvue + picker

    用mpvue框架和原生的微信小程序有一定差异性,之前在做选择器的时候用原生的方法怎么都不行,最后找到了解决办法。

    数据为数组,代码如下:

    <template>
      <div class="cost-estimation">
        <view class="section">
          <picker mode="selector" @change="bindPickerChange" :index="index" :range="array">
            <view>
              当前选择的国家:{{array[index]}}
            </view>
          </picker>
        </view>
      </div>
    </template>

    <script>
    export default {
      data () {
        return {
          array: ['中国', '美国', '日本', '韩国'],
          index: 0
        }
      },
      methods: {
        bindPickerChange: function (e) {
          console.log('picker发送选择改变,携带值为', e)
          this.index = e.mp.detail.value
        }
      }
    }
    </script>
     
    数据为数组对象,代码如下:
    <template>
      <div class="cost-estimation">
        <view class="section">
          <picker mode="selector" @change="bindPickerChange" :index="index" :range="objectarray" :range-key="'name'">
            <view>
              当前选择的国家:{{objectarray[index].name}}
            </view>
          </picker>
        </view>
      </div>
    </template>

    <script>
    export default {
      data () {
        return {
          objectarray: [
            {
              id: 1,
              name: '中国'
            },
            {
              id: 1,
              name: '美国'
            },
            {
              id: 1,
              name: '日本'
            },
            {
              id: 1,
              name: '韩国'
            }
          ],
          index: 0
        }
      },
      methods: {
        bindPickerChange: function (e) {
          this.index = e.mp.detail.value
        }
      }
    }
    </script>
     
    注意: 1、在 mpvue 中 template 部分不是 bindchange 也不是 @click
                2、数据为数组对象时,range-key 对应的 'name' 要加引号
  • 相关阅读:
    CSS Friendly Control Adapters CSSFriendly.dll
    2008秋季计算机软件基础未交实验报告名单
    About NeatHtml™ Brettle.Web.NeatHtml.dll
    What is DotNetOpenMail DotNetOpenMail.dll
    What is the simplest way to distribute a .NET COM server to any platform?
    页面压缩 Enabling Gzip and Deflate HTTP Compression in ASP.NET pages(转)
    [算法分析]计数排序
    [置顶] EJDesktop开源项目
    继承初体验
    [置顶] 基于stm32f103zet6之UC/OS_II的学习1(初步移植OS点灯大法)
  • 原文地址:https://www.cnblogs.com/Nxx-clara/p/11610954.html
Copyright © 2011-2022 走看看