当前位置:首页 > 技术文章 > 正文内容

使用uniapp开发小程序遇到的一些问题及解决方法

zonemu23小时前技术文章2

1、swiper组件自定义知识点

swiper组件的指示点默认是圆圈,想要自己设置指示点,需要获得当前索引,然后赋给当前索引不同的样式,然后在做个动画就可以了。
*
关键点
用change方法,然后通过e.detail.current获得索引

***示例

  <!-- 顶部滑块区域 -->
    <view class="swiper">
      <swiper
        class="swiper"
        :autoplay="true"
        :interval="3000"
        :duration="500"
        @change="changeSwiper"
      >
        <swiper-item v-for="item in banner" :key="item.cover_display">
          <view class="swiper-image">
            <image :src="item.cover_display" />
          </view>
        </swiper-item>
      </swiper>
      <!-- 轮播指示点样式修改 -->
      <view class="dots">
        <view v-for="(item, index) in banner.length" :key="index">
          <view
            class="dot"
            :class="index === swiperCurrent ? ' active' : ''"
          />
        </view>
      </view>
    </view>
12345678910111213141516171819202122232425
 // 监听滑块索引的改变
    changeSwiper(e) {
      this.swiperCurrent = e.detail.current
    },
1234
/* 指示点样式修改 */
.dots {
  position: absolute;
  width: 100%;
  height: 8rpx;
  bottom: 36rpx;
  z-index: 199;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.dot {
  width: 20rpx;
  height: 8rpx;
  transition: all 0.5s;
  background-color: #ffffff;
  margin-right: 10rpx;
}
.active {
  width: 40rpx;
  height: 8rpx;
  background-color: #306de9;
}
1234567891011121314151617181920212223

2、修改botton边框

uniapp里面botton的边框是不能直接修改的,需要修改其after
示例

.card-button::after {
  border: none;
}
123

3、uni.navigateTo失效问题

如果要跳转的路由属于tabBar中,那么不能使用uni.navigateTo,需要使用uni.switchTab。
示例

uni.switchTab({
     url: '../home/index'
})
123

4、input数据双向绑定问题

在小程序中input组件中的数据不会实时反应,需要开发手动赋值更新
示例

   <!--输入框部分-->
        <view class="edit-traveler-input-box">
          <text>{{ language === "EN" ? "姓名" : "First Name" }}</text>
          <input
            :placeholder="
              language === 'EN' ? '在此输入姓名' : '在此输入名字,例如jia jia'
            "
            :value="setData.first_name"
            data-model="first_name"
            type="value"
            placeholder-class="placeholder"
            @blur="changeInput"
          >
          <view
            :class="language === 'EN' ? 'EN-class' : 'CN-class'"
            @click="changeLanguage"
          >{{ language }}</view>
          <image src="@/static/image/default/contacts/contacts.png" />
        </view>
        <view v-if="language === 'CN'" class="edit-traveler-input-box">
          <text>Last Name</text>
          <input
            placeholder="在此输入姓氏,例如Guo"
            placeholder-class="placeholder"
            :value="setData.last_name"
            data-model="last_name"
            type="value"
            @blur="changeInput"
          >
        </view>
        <view class="edit-traveler-input-box">
          <text>联系方式</text>
          <input
            placeholder="在此输入联系方式"
            placeholder-class="placeholder"
            :value="setData.telephone"
            data-model="telephone"
            type="value"
            @blur="changeInput"
          >
        </view>
        <view class="edit-traveler-input-box">
          <text>{{ myMap[id_type] }} </text>
          <input
            :placeholder="
              id_type === 'GovernmentId' ? '在此输入身份证' : '在此输入护照'
            "
            placeholder-class="placeholder"
            :value="setData.id_no"
            data-model="id_no"
            type="value"
            @blur="changeInput"
          >
          <image
            src="@/static/image/default/contacts/transformation.png"
            @click="changeID"
          />
        </view>
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
data() {
    return {
      hideModal: false, // 模态框的状态  true-隐藏  false-显示
      animationData: {}, //
      val: 0,
      language: 'EN',
      id_type: 'GovernmentId',
      myMap: this.$myMap,
      uid: null,
      setData: {
        id_no: '',
        telephone: '',
        first_name: '',
        last_name: ''
      }
    }
  },
methods: {
  // 同步input
    changeInput(e) {
      const item = e.currentTarget.dataset.model
      this.setData[item] = e.detail.value
    }
}
123456789101112131415161718192021222324

5、input中value 属性设置不生效的问题

当重复设置某些属性为相同的值时,不会同步到view层。
解决方法可以参考:解决方法value 属性设置不生效
或者直接在得到焦点时清空,失去焦点时赋值

6、调用一些第三接口需要写在button中并定义 open-data

示例:getUserInfo

 <button open-type="getUserInfo" class="rectangle" @click="getUserInfo">
1

7、ios底部使用绝对定位,上面使用margin-bottom相间隔会有回弹问题

解决办法使用padding-bottom

8、强制更新

有时候会遇到数据更新了,但是view视图部分没有更新的情况,这时候可以使用强制刷新。

this.$forceUpdate()

相关文章

linux发行版-openSUSE Agama 15安装程序发布:带来多项可用性升级

openSUSE旗下仍在开发中的全新Linux安装工具Agama,于近日推出v15版本,带来了界面增强、实用新功能等一系列改进,为用户带来更顺畅的系统安装体验!界面优化:细节之处见用心新版本在本地化设...

Linux发行版Nobara更新39版本,号称“专为游戏玩家定制”

IT之家 12 月 27 日消息,Linux 发行版 Nobara 今天推出了 39 版本,主要改进了“Gamescope 合成器”,并更新了 OBS Studio、部分驱动程序及 Nautilus...

崩溃!3 道 React 面试必卡题,吃透稳过金九银十

凌晨三点还在对着 “React 组件为什么重复渲染” 抓耳挠腮?别慌!今天挑出 3 道让 90% 候选人卡壳的高频题,全是大厂面试官挖的 “坑”,手把手教你见招拆招,看完直接装进面试 “弹药库”!先问...

Vue3开发极简入门(15.1):emits补完-结合v-model

之前代码是通过按钮触发emit,如果希望输入框里的内容在输入之后也能同步到父组件,就可以结合v-model的update事件来操作,具体如下。Son2.vue:<template>...

快速上手React(快速上手的高级表达)

web前端三大主流框架1、Angular大家眼里比较牛的框架,甚至有人说三大框架中只有它能称得上一个完整的框架,因为它包含的东西比较完善,包含模板,数据双向绑定,路由,模块化,服务,过滤器,依赖注入等...

10个实例小练习,快速入门熟练 Vue3 核心新特性(一)

作者:xuying 全栈修炼转发链接:https://mp.weixin.qq.com/s/_n2seDbbiO5hXQfuUGbUCQ前言Vue3.0 发 beta 版都有一段时间了,正式版也不远了...