uniapp使用及踩坑项目记录

news2024/9/17 9:15:15

环境准备

下载 HBuilderX

在这里插入图片描述
在这里插入图片描述
使用命令行创建项目:
在这里插入图片描述
在这里插入图片描述

一些常识准备

响应式单位rpx

当设计稿宽度为750px的时,1rpx=1px。

uniapp中vue文件style不用添加scoped

打包成h5端的时候自动添加上去,打包成 微信小程序端 不需要添加 scoped。

图片的使用

background: url(‘~@/static/bg.png’)
src=“~@/static/api.png”

小程序背景图片会默认转为base64格式的

使用动态文件的时候要用相对路径
不以/开头的都是相对路径
以/开头的都是绝对路径
在这里插入图片描述

项目文件树分析

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

碰到的问题及处理方法

sitemap 索引情况提示] 根据 sitemap 的规则[0],当前页面 [pages/tabBar/component/component] 将不被索引

在这里插入图片描述
解决方法:
manifest.jsonsetting中添加"checkSiteMap": false
在这里插入图片描述
注意:这里要切换到源码视图修改才会生效
在这里插入图片描述

TypeError: Cannot read property ‘forceUpdate’ of undefined

这个报错的原因是appid失效了。
在这里插入图片描述
解决方法:

  1. 百度搜索 微信公众平台
  2. 微信公众平台 - 设置(左侧菜单) - 往下滑
    在这里插入图片描述

创建页面(初始页面)

引导页:

  1. 创建引导页
    在这里插入图片描述
  2. 配置引导页跳转到tabBar页面
    在这里插入图片描述

添加全局样式(Sass)

方法一

在这里插入图片描述
注意:重新运行项目的时候可能会报错
在这里插入图片描述
重新安装一下缺少的那个包就好了
在这里插入图片描述
创建全局样式表:
在这里插入图片描述
全局引入全局样式表:
在这里插入图片描述

使用:在这里插入图片描述
碰到的错误:SassError: Undefined variable.
在这里插入图片描述
不知道怎么解决~~~~

方法二(创建全局样式文件)

创建全局样式文件main.scss文件,然后在App.vue中引入全局样式文件文件。
在这里插入图片描述

封装公共请求方法

在src下创建common文件夹,将公共求方法request.ts文件放在common文件夹中。
在这里插入图片描述

不带token的公共请求方法

// 根地址
let baseUrl = 'https://XXX.com';

// 公共方法
const publicFun = (opts, data) => {
    // 判断是否有网
    uni.onNetworkStatusChange(function (res) {
        if (!res.isConnected) {
            uni.showToast({
                title: '网络连接不可用!',
                icon: 'none'
            });
        }
        return false
    });
    // 根据请求方法设置不同的请求头信息
    let httpDefaultOpts = {
        url: baseUrl + opts.url,
        data: data,
        method: opts.method,
        header: opts.method == 'get' ? {
            'X-Requested-With': 'XMLHttpRequest',
            "Accept": "application/json",
            "Content-Type": "application/json; charset=UTF-8"
        } : {
            'X-Requested-With': 'XMLHttpRequest',
            'Content-Type': 'application/json; charset=UTF-8'
        },
        dataType: 'json',
    }
    // 返回请求头信息
    return httpDefaultOpts;
}

// promise 请求
const promiseRequest = (requestHead) => {
    let promise = new Promise(function (resolve, reject) {
        uni.request(requestHead).then(
            (res) => {
                resolve(res.data)
            }
        ).catch(
            (response) => {
                reject(response)
            }
        )
    })
    return promise
}


// 请求方法
const get = (url) => {
    const requestBody = {url, method: 'get'}
    const params = publicFun(requestBody);
    return promiseRequest(params);
}

const post = (url) => {
    const requestBody = {url, method: 'post'}
    const params = publicFun(requestBody);
    return promiseRequest(params);
}

export default {
    baseUrl,
    get,
    post
}

使用:
在这里插入图片描述

import request from '@/common/request';

// 请求方法调用
request.post('/company/getVerificationCode').then(res => {
  console.log({res})
});

带token的公共请求方法

// 根地址
let baseUrl = 'https://XXX.com';

// 公共方法
const publicFun = (opts, data) => {
    // 判断是否有网
    uni.onNetworkStatusChange(function (res) {
        if (!res.isConnected) {
            uni.showToast({
                title: '网络连接不可用!',
                icon: 'none'
            });
        }
        return false
    });
    // 获取token
    let token = uni.getStorageSync('token');
    // 处理token
    if (token == '' || token == undefined || token == null) {
        uni.showToast({
            title: '账号已过期,请重新登录',
            icon: 'none',
            complete: function() {
                uni.reLaunch({
                    url: '/pages/init/init'
                });
            }
        });
    } else {
        // 根据请求方法设置不同的请求头信息
        let httpDefaultOpts = {
            url: baseUrl + opts.url,
            data: data,
            method: opts.method,
            header: opts.method == 'get' ? {
                'X-Access-Token': token,
                'X-Requested-With': 'XMLHttpRequest',
                "Accept": "application/json",
                "Content-Type": "application/json; charset=UTF-8"
            } : {
                'X-Access-Token': token,
                'X-Requested-With': 'XMLHttpRequest',
                'Content-Type': 'application/json; charset=UTF-8'
            },
            dataType: 'json',
        }
        // 返回请求头信息
        return httpDefaultOpts;
    }
}

// promise 请求
const promiseRequest = (requestHead) => {
    let promise = new Promise(function (resolve, reject) {
        uni.request(requestHead).then(
            (res) => {
                resolve(res.data)
            }
        ).catch(
            (response) => {
                reject(response)
            }
        )
    })
    return promise
}


// 请求方法
const get = (url) => {
    const requestBody = {url, method: 'get'}
    const params = publicFun(requestBody);
    return promiseRequest(params);
}

const post = (url) => {
    const requestBody = {url, method: 'post'}
    const params = publicFun(requestBody);
    return promiseRequest(params);
}

export default {
    baseUrl,
    get,
    post
}

支持ts写法版本

// 根地址
let baseUrl = import.meta.env.VITE_APP_API_BASE_URL;

// 公共方法
const publicFun = (opts: any, data: any) => {
    // 判断是否有网
    uni.onNetworkStatusChange(function (res) {
        if (!res.isConnected) {
            uni.showToast({
                title: '网络连接不可用!',
                icon: 'none'
            });
        }
        return false
    });
    // 获取token
    let token = uni.getStorageSync('token');
    // 处理token
    if (token == '' || token == undefined || token == null) {
        uni.showToast({
            title: '账号已过期,请重新登录',
            icon: 'none',
            complete: function () {
                uni.reLaunch({
                    url: '/pages/init/init'
                });
            }
        });
    } else {
        // 根据请求方法设置不同的请求头信息
        let httpDefaultOpts = {
            url: baseUrl + opts.url,
            data: data,
            method: opts.method,
            header: opts.method == 'get' ? {
                'Authorization': 'Bearer ' + token,
                'X-Requested-With': 'XMLHttpRequest',
                "Accept": "application/json",
                "Content-Type": "application/json; charset=UTF-8"
            } : {
                'Authorization': 'Bearer ' + token,
                'X-Requested-With': 'XMLHttpRequest',
                'Content-Type': 'application/json; charset=UTF-8'
            },
            dataType: 'json',
        }
        // 返回请求头信息
        return httpDefaultOpts;
    }
}

// promise 请求
const promiseRequest = (requestHead: any) => {
    let promise = new Promise(function (resolve, reject) {
        uni.request({
            ...requestHead,
            success: (res) => {
                resolve(res);
            },
            fail: (err: any) => {
                reject(err)
            }
        });
    })
    return promise
}


// 请求方法
const get = (url: string) => {
    const requestBody = {url, method: 'get'}
    const params = publicFun(requestBody, '');
    return promiseRequest(params);
}

const post = (url: string, data: any) => {
    const requestBody = {url, method: 'post'};
    const params = publicFun(requestBody, data);
    return promiseRequest(params);
}

export default {
    baseUrl,
    get,
    post
}

将封装的方法挂载在原型上

挂载:
在这里插入图片描述
调用:
在这里插入图片描述
在这里插入图片描述

小程序登录

在微信公众平台注册测试号
在这里插入图片描述
在这里插入图片描述
将测试号的地址放在后台配置上就可以实现登录了。
在这里插入图片描述
前台登录的时候要获取小程序的信息:
在这里插入图片描述

<!-- getPhoneNumber 获取用户手机号 -->
<!-- https://developers.weixin.qq.com/miniprogram/dev/component/button.html -->
<button class="primary-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">点击微信登录</button>
export default class Login extends Vue {
  // 用户类型
  authorType: string | undefined = '';

 // 
  sessionData: any | undefined = null;

  created(): void {
    uni.login({
      // 使用微信登录
      provider: 'weixin',
      success: (res) => {
        if (res.errMsg == 'login:ok' && res.code) {
          // 请求接口 获取用户登录信息 
          // 注意: onlyAuthorize:true 才会返回
          this.sessionData = res.data;
        }
      }
    })
  }

   getPhoneNumber(e) {
		// 获取用户登录的身份
	    const authorType = uni.getStorageSync('authorType');
	    if (e.detail.errMsg != 'getPhoneNumber:ok') {
	      uni.showToast({
	        title: '获取手机号失败',
	        icon: 'none'
	      })
	      return;
	    }
	    
	    // 判断手机号是否获取成功
	    WechatLoginController.decodePhone(this.$axios, {encryptedData: e.detail.encryptedData, iv: e.detail.iv, sessionkey: this.sessionData.session_key}).then(result => {
	      if (result.errMsg == 'request:ok') {
	      	// 通过拿到的信息 调用接口登录
	      	// 通过用户类型和手机号登录
	        WechatLoginController.authorLogin(this.$axios, authorType, result.data.phoneNumber).then(result => {
	          if (result.errMsg == 'request:ok') {
	            uni.setStorage({key: "token", data: result.data});
	            // 登录跳转到首页
	            uni.switchTab({
	              url: '/pages/tabBar/home/home'
	            });
	          }
	        })
	      } else {
	      	// 获取失败
	        uni.showToast({
	          title: '获取手机号失败',
	          icon: 'none'
	        })
	        return;
	      }
	    })
	}
}

配置地址映射

创建.env.development.env.production文件配置根路由地址。
在这里插入图片描述
在这里插入图片描述
使用:通过import.meta.env来使用。
在这里插入图片描述

多语言

  1. 安装vue-i18n,npm install vue-i18n
    在这里插入图片描述
  2. 创建i18n文件存放多语言翻译文件
    在这里插入图片描述
    在这里插入图片描述
  3. 配置vue-i18n

在这里插入图片描述

import {createSSRApp} from "vue";
import App from "./App.vue";
import axios from '@/common/axios';
import {createI18n, useI18n} from "vue-i18n";
import * as zh from '@/i18n/lang/zh'
import * as en from '@/i18n/lang/en'

const i18n = createI18n({
    locale: 'zh-cn',
    legacy: false,
    globalInjection: true,
    fallbackLocale: 'zh-cn',
    messages: {
        'zh-cn': zh,
        'en': en
    }
});

const systemI18n = {
    setup() {
        const {locale, t} = useI18n();
        return {locale, t};
    }
};

export function createApp() {
    const app = createSSRApp(App, systemI18n);

    app.use(i18n);
    // 挂载到全局的每一个Vue实例上
    app.config.globalProperties.$axios = axios;

    return {
        app
    };
}
  1. 使用
    在这里插入图片描述
    这里用的就是demandState里面的值
    在这里插入图片描述

自定义组件

在src下创建components文件夹,把创建的组件存放在components中,然后就可以全局使用了,不用导入,也不用注册,直接通过自定义组件文件名称来使用,vit会自动识别components中的文件为组件。
在这里插入图片描述
由于vue3中不支持require,所以我就用自定义组件的方式, 通过利用image的error方法来实现了图片加载失败的占位效果。

<template>
    <image v-if="showErrorImage || imgUrl.length == 0" :class="classVal" src="~@/static/task/task.png" mode="widthFix"></image>
    <image v-if="!showErrorImage && imgUrl.length > 0" :class="classVal" :src="imgUrl"  @error="imageError()" mode="widthFix" ></image>
</template>

<script setup>
import { defineProps, ref } from "vue";

const props = defineProps({
  imgUrl: {
    type: String,
    default: ""
  },
  classVal: {
    type: String,
    default: ""
  }
});

let showErrorImage = ref(false);

const imageError = () => {
  showErrorImage.value = true;
}
</script>

<style lang="scss">

</style>

也可以通过下面这种方式写,我是用自定义组件是因为调用接口的方法不支持内容的修改。
在这里插入图片描述

通过VueX自定义提示

uniapp的uni-popup-message和wx.showToast等的局限性太多了,就自己弄了一个$toast实现自定义提示,但是每次使用的时候都要在页面上写一下CustomToast这个标签,麻了。
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

代码:
main.ts

import {createSSRApp} from "vue";
import App from "./App.vue";
import store from "@/store";

// 提示加载方法
function toast(params: any){
    store.commit("toast", params)
}

export function createApp() {
    const app = createSSRApp(App);
    // 挂载到全局的每一个Vue实例上
    app.config.globalProperties.$store = store;
    app.config.globalProperties.$toast = toast;

    return {
        app
    };
}

src/store/index.ts 内容:

import Vuex from 'vuex';
const store = new Vuex.Store({
    state: {
        type: '',
        message: '',
        isVisible: false
    },
    mutations: {
        toast(state, params){
            if (params) {
                state.type = params.type;
                state.message = params.message;
                state.isVisible = true;
                if (params.timeout) {
                    setTimeout(() => {
                        state.isVisible = false;
                    }, params.timeout)
                } else {
                    setTimeout(() => {
                        state.isVisible = false;
                    }, 1000)
                }
            }
        }
    }
})
export default store

CustomToast组件内容:
注意uniapp中把项目组件放在components文件夹中,可以在全局中使用。

<template>
  <view v-if="isVisible" class="toast" :class="type">
    <view class="content">{{message}}</view>
  </view>
</template>
<script lang="ts">
import {Options, Vue} from "vue-class-component";
import store from "@/store";
import { computed } from "vue";

@Options({
  components: {
  },
})

export default class CustomToast extends Vue {
  created() {
  }

  type = computed(() => {
    return store.state.type;
  });

  isVisible = computed(() => {
    return store.state.isVisible;
  });

  message = computed(() => {
    return store.state.message;
  });

  toast(){
    this.$store.commit("toast");
  }
}
</script>

<style lang="scss">
.toast {
  position: fixed;
  top: 4vh;
  left: 50%;
  transform: translateX(-50%);
  width: 90vw;
  border-radius: 8rpx;
  background: red;
  .content {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
    margin: 18rpx;
    line-height: 40rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    font-size: 24rpx;
  }
}

.error {
  color: #f56c6c;
  background: #fde2e2;
}
.success {
  color: #09bb07;
  background: #e1f3d8;
}
.warn {
  color: #e6a23c;
  background: #faecd8;
}
</style>

使用:

<template>
  <view class="add-info">
    <button type="primary" hover-class="none" @click="submit()">保存</button>
    <!-- 引入组件 -->
    <CustomToast></CustomToast>
  </view>
</template><script lang="ts">
import {Options, Vue} from "vue-class-component";
import {onLoad} from "@dcloudio/uni-app";

@Options({
  components: {
  },
})

export default class SupplementAdd extends Vue {
  submit() {
  	// 显示组件
    this.$toast({type: 'warn', message: '请输入正确格式的代码'})
  }
}
</script>

动态渲染图片

只能使用绝对路径。
在这里插入图片描述

uni-segmented-control 和 swiper实现左右滑动点击切换

在这里插入图片描述

  <view class="segmented">
    <uni-segmented-control :current="current" :values="items" styleType="button" activeColor="#4699FA"
                           @clickItem="onClickItem"></uni-segmented-control>
  </view>
  <view class="equipment-content">
    <swiper class="swiper" style="height: calc(100vh - 172rpx);" duration="500" @change="swiperChange"
            :current="current">
      <swiper-item>
        <scroll-view v-if="current === 0" style="height: 100%;" scroll-y="true"
                     @scrolltolower="loadingMore('1')" @scrolltoupper="refresh()">
          1
          </scroll-view>
      </swiper-item>
      <swiper-item>
        <scroll-view v-if="current === 1" style="height: 100%;" scroll-y="true"
                     @scrolltolower="loadingMore('2')" @scrolltoupper="refresh()">
          2
          </scroll-view>
      </swiper-item>
      <swiper-item>
        <scroll-view v-if="current === 2" style="height: 100%;" scroll-y="true"
                     @scrolltolower="loadingMore('3')" @scrolltoupper="refresh()">
          3
          </scroll-view>
      </swiper-item>
    </swiper>
  </view>           
items = ['评审邀请', '参与评审的任务', '完成评审的任务'];
current = 0;

// uni-segmented-control 点击切换
onClickItem(e) {
 if (this.current !== e.currentIndex) {
   this.current = e.currentIndex
 }
}

// swiper 左右滑动切换
swiperChange(e) {
 this.current = e.detail.current;
}

在这里插入图片描述
将右边改造成左边的样子。

::v-deep(.segmented-control) {
  height: 88rpx;
}

::v-deep(.segmented-control__text) {
  color: #000 !important;
}

::v-deep(.segmented-control__item--button--first),
::v-deep(.segmented-control__item--button) {
  background-color: #fff !important;
  border-color: #fff !important;
}

::v-deep(.segmented-control__item--button--active .segmented-control__text) {
  padding-bottom: 14rpx;
  color: #4699FA !important;
}

::v-deep(.segmented-control__item--button--active .segmented-control__text::after) {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  content: "";
  display: block;
  width: 28rpx;
  height: 6rpx;
  background: #4699FA;
  border-radius: 3rpx;
}

.segmented {
  padding-bottom: 10rpx;
  box-shadow: inset 0px -1px 0px 0px rgba(0, 0, 0, 0.08);
}

全局过滤器

在common文件夹中创建filters.ts文件,将文件的内容挂载到原型上,然后通过$filters.filterValueData()的方式来使用。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

switchTab 跳转不能传参

可以通过全局变量的方式来使用。
存储:
在这里插入图片描述

 viewCategores(categoryName) {
 	// 将要传递的参数存储为全局变量
    getApp().globalData.categoryName = categoryName;
    uni.switchTab({
      url: '/pages/tabBar/found/found'
    })
  }

接收/使用:
在这里插入图片描述

// 接收传递的参数
getApp().globalData.categoryName

注意:这样使用数据只会更新一次。

解决方法:将switchTab更换为reLaunch。
在这里插入图片描述

navigateTo 跳转传递多个参数

在这里插入图片描述
注意:navigateTo 传递的参数是string类型的,传递的时候要通过JSON.stringify转换为字符串之后使用。

<uni-list-item v-for="item in pagination.content" link="navigateTo" :to="'/pages/customer/other/questionnaire/detail/detail?itemStr='+ JSON.stringify(item)">
// 接收传递的参数
created() {
	// 这里 onLoad 只加载一次,
	// 页面每次加载都加载数据接口 用 onShow
    onLoad((option) => {
      let options = JSON.parse(option.itemStr);
    })
}

通过点击事件跳转

<uni-list-item v-for="item in pagination.content" @click="viewQuestionnaireDetail(item)" link>
</uni-list-item>
viewQuestionnaireDetail(item: any) {
    CustomerQuestionnireController.getQuestionnaireLogByQuestIdAndAccountId(this.$axios, item.questId).then(res => {
      if (res.data) {
        wx.showToast({
          title: '当前调查项已经填写过了!',
          icon: 'none',
          duration: 500
        })
      } else {
        uni.navigateTo({
          url: '/pages/customer/other/questionnaire/detail/detail?itemStr='+ JSON.stringify(item)
        })
      }
    })
  }

在这里插入图片描述

navigateTo 跳转次数超过10次栈溢出

在这里插入图片描述
解决方法:
通过 getCurrentPages().length 判断次数,超过之后用reluanch实现跳转。

在这里插入图片描述

uni-data-picker 数据显示不出来

v-model绑定的数据必须要有值才行。
在这里插入图片描述

机型判断

uniapp种通过uni.getSystemInfoSync().platform来判断运行环境的机型。

百度小程序开发工具、微信小程序开发工具、支付宝(Alipay )小程序开发工具中uni.getSystemInfoSync ().platform的返回值都是devtools。

表单

简单表单的校验

在这里插入图片描述

  <uni-forms ref="baseForm" :rules="baseFormRules" :model="baseFormData">
  	  <!--注意:这里必须要写name校验才会生效 -->
      <uni-forms-item required label="用户名" name="accountName">
        <uni-easyinput v-model="baseFormData.accountName" placeholder="请输入用户名"/>
      </uni-forms-item>
      <!--localdata 只支持 localdata: {text: '显示文本', value: '选中后的值', disable: '是否禁用'} 这样格式的数据-->
      <uni-data-select
            v-model="baseFormData.technicalTitle"
            :localdata="technicalTitles"
        ></uni-data-select>
</uni-forms>
<button type="primary" hover-class="none" @click="submit('baseForm')">提交</button>
baseFormData = {
    accountName: '',
    technicalTitle: '',
};
baseFormRules = {
    accountName: {
      rules: [
        {
          required: true,
          errorMessage: '请输入用户名',
        }
      ]
    }
}
// 提交
  submit(ref) {
    this.$refs[ref].validate((err,value)=>{
      if(err) {
        // 修改失败
        wx.showToast({
          title: '请填写正确格式的信息',
          icon: 'error',
          duration: 1000
        });
      } else {
        // 修改成功
      }
    })
  }

动态表单校验

<uni-forms ref="dynamicForm" :rules="dynamicRules" :model="dynamicFormData">
	<uni-forms-item label="邮箱" required name="email">
		<uni-easyinput v-model="dynamicFormData.email" placeholder="请输入姓名" />
	</uni-forms-item>
	<template v-for="(item,index) in dynamicFormData.domains">
		<uni-forms-item :label="item.label+' '+index" required
			:rules="[{'required': true,errorMessage: '域名项必填'}]" :key="item.id"
			:name="['domains',index,'value']">
			<view class="form-item">
				<uni-easyinput v-model="dynamicFormData.domains[index].value" placeholder="请输入域名" />
				<button class="button" size="mini" type="default" @click="del(item.id)">删除</button>
			</view>
		</uni-forms-item>
	</template>

</uni-forms>
<view class="button-group">
	<button type="primary" size="mini" @click="add">新增域名</button>
	<button type="primary" size="mini" @click="submit('dynamicForm')">提交</button>
</view>
export default {
	data() {
		return {
			// 数据源
			dynamicFormData: {
				email: '',
				domains: []
			},
			// 规则
			dynamicRules: {
				email: {
					rules: [{
						required: true,
						errorMessage: '域名不能为空'
					}, {
						format: 'email',
						errorMessage: '域名格式错误'
					}]
				}
			}
		}
	},
	methods: {
		// 新增表单域
		add() {
			this.dynamicFormData.domains.push({
				label: '域名',
				value:'',
				id: Date.now()
			})
		},
		// 删除表单域
		del(id) {
			let index = this.dynamicLists.findIndex(v => v.id === id)
			this.dynamicLists.splice(index, 1)
		},
		// 提交
		submit(ref) {
			this.$refs[ref].validate((err,value)=>{
				console.log(err,value);
			})
		},
	}
}

uni-list-item 点击事件不生效

解决给uni-list-item添加上link属性。
在这里插入图片描述
加了link之后,通过:showArrow="false"去除不了右箭头, 如果不需要右箭头可以使用clickable来实现。
在这里插入图片描述

Error: MiniProgramError {“errMsg”:“navigateTo:fail webview count limit exceed”}

小程序中页面栈最多十层。
通过getCurrentPages().length来判断页面栈有多少层,大于9层的时候通过reLaunch来跳转,其他的时候通过navigateTo来跳转。
在这里插入图片描述

‘default’ is not exported by node_modules/vue-class-component/dist/vue-class-component.esm-bundler.js, imported by node_modules/vue-property-decorator/lib/index.js

Vue3 extends 写法 @Prop 报错。

处理导入prop包时要导入到具体的包。

通过 import { Prop } from "vue-property-decorator/lib/decorators/Prop";来导入Prop。
在这里插入图片描述

[Component] : should have url attribute when using navigateTo, redirectTo or switchTab(env: macOS,mp,1.06.2210310; lib: 2.27.2)

使用navigator标签实现跳转的时候要加上open-type
在这里插入图片描述

uniapp 小程序 vue3使用echarts

小程序是不支持echarts的,那么怎么使用图表呢?
在这里插入图片描述

  1. 导入echarts,npm i echarts
  2. 使用lime-echart插件 插件地址
    在这里插入图片描述
<template>
  <view class="charts">
    <l-echart ref="chart" @finished="init()"></l-echart>
  </view>
</template>

<script lang="ts">
import {Options, Vue} from "vue-class-component";
import {onLoad} from "@dcloudio/uni-app";
// 代码插件 https://ext.dcloud.net.cn/plugin?id=4899
import * as echarts from 'echarts';
import LEchart from '@/components/l-echart/l-echart';

@Options({
  components: {
    LEchart
  },
})

export default class Detail extends Vue {
  config = {
    xAxis: {
      type: 'category',
      data: ['12.02', '12.03', '12.04', '12.05', '12.06', '12.07'],
      axisLabel: {
        color: "rgba(0, 0, 0, 0.45)"
      },
      axisLine: {
        lineStyle: {
          color: 'rgba(0, 0, 0, 0.15)'
        }
      }
    },
    color: '#5AD8A6',
    yAxis: {
      type: 'value',
      name: "(bmp)",
      axisLabel: {
        color: "rgba(0, 0, 0, 0.45)"
      }
    },
    series: [
      {
        data: [150, 230, 224, 218, 135, 147, 260],
        type: 'line'
      }
    ]
  };

  created() {
    onLoad((option) => {
      uni.setNavigationBarTitle({
        title: option.title
      });
    });
  }

  init() {
    this.$refs.chart.init(echarts, chart => {
      chart.setOption(this.config);
    });
  }

}
</script>

<style>
.charts {
  width: 375px;
  height: 375px;
}
</style>

测试号真机调试

准备条件:

  1. 测试号(在微信开发者工具中将测试号修改成自己申请的测试号)
    在这里插入图片描述

  2. 本机ip地址(将之前配置的地址映射使用的地址换成本机的ip地址)
    在这里插入图片描述

利用swiper实现3d轮播

在这里插入图片描述

<swiper class="swiper" previous-margin="45rpx" next-margin="45rpx" circular @change="swiperChange" :current="current">
 <swiper-item class="item" v-for="(item, index) in sceneList" :key="index">
   <view class="content-block" :class="{'actived': current == index}">
     {{index}}
   </view>
 </swiper-item>
</swiper>
current = 1;

sceneList = [
  { img: '/static/1.png' },
  { img: '/static/2.png' },
  { img: '/static/3.png' },
  { img: '/static/4.png' }
];
  
// swiper 左右滑动切换
swiperChange(e) {
  console.log({e})
  this.current = e.detail.current;
}
.swiper {
  width: 750rpx;
  height: 350rpx;
  .item {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 630rpx;
    height: 256px;
    .content-block {
      width: 630rpx;
      height: 256rpx;
      background-color: #fff;
      box-shadow: 0 3rpx 13rpx 0 rgba(0,0,0,0.08);
      border-radius: 6rpx;
      transition: height .5s ease 0s;
      &.actived {
        height: 320rpx !important;
        background: #FFFFFF;
        box-shadow: 0 4rpx 16rpx 0 rgba(0,0,0,0.08) !important;
        border-radius: 8rpx !important;
      }
    }
  }
}

页面问题

uni-easyinput text-align:end 真机调试不生效

在这里插入图片描述
在这里插入图片描述
在写样式控制的时候用text-align:right

uni-easyinput type=“textarea” placeholder 层级问题

这个问题只在安卓上有,ios是正常的。
在这里插入图片描述

通过 cover-view 来解决

cover-view 是不支持嵌套input的。
在这里插入图片描述
在这里插入图片描述

出现弹框时将uni-easyinput的类型改为 text

这种方法反应有延迟,select只有一个change事件。
在这里插入图片描述

封装一个textarea

通过view标签来代替不点击输入时的状态。

去除uniapp button自带边框

button {
  &::after{
    border: initial;
  }
}

去除uni-list-chat的边框

在这里插入图片描述

<uni-section titleFontSize="28" class="comments" title="全部评论(2)" type="line">
  <!-- 重点  :border="false"-->
  <uni-list :border="false">
    <uni-list-chat avatar="@/static/dashboard/icon1.png" :avatar-circle="true" >
      <view class="chat-custom-right">
        <view class="name">郝沸怀</view>
        <view class="comments-content">都是大佬</view>
        <view class="time">1天前</view>
      </view>
    </uni-list-chat>
    <uni-list-chat avatar="@/static/dashboard/icon1.png" :avatar-circle="true" >
      <view class="chat-custom-right">
        <view class="name">郝沸怀</view>
        <view class="comments-content">都是大佬</view>
        <view class="time">1天前</view>
      </view>
    </uni-list-chat>
  </uni-list>
</uni-section>

然后通过阴影来给uni-section下添加分割线,达到如下效果
在这里插入图片描述

::v-deep(.uni-section-header) {
   box-shadow: inset 0px -1px 0px 0px rgba(0,0,0,0.08);
 }

uni-list-item 使用link跳转,右箭头不能去除

在这里插入图片描述
解决方法:
使用clickable来实现跳转。
在这里插入图片描述
这样虽然能跳转,但是点击uni-list-item点击的时候uni-list-item有一个黑色背景,可以通过把点击时间写在slot自定义内容上,点击时就不会有背景色了。
在这里插入图片描述
有时候会有点击态效果,可以通过设置它的背景色来去除。
在这里插入图片描述

uni-data-checkbox 字段映射

text是显示的值,value是选中后显示的绑定的id值, 和v-model绑定的categoryData息息相关。
在这里插入图片描述
在这里插入图片描述

修改uni-data-checkbox默认样式

在这里插入图片描述

.uni-data-checklist .checklist-group .checklist-box.is--tag {
  padding: 14rpx 24rpx !important;
  border: none !important;
  background: #f6f6f6 !important;
  border-radius: 28rpx !important;
  &.is-checked {
    background-color: #e8efff !important;
  }
}

改完之后的样子:
在这里插入图片描述

通过 repeating-conic-gradient 实现表盘过渡

在这里插入图片描述
样式:

background: repeating-conic-gradient(rgba(255, 255, 255, .6) 0, rgba(255, 255, 255, .6) .8deg, transparent 1deg, transparent calc((360 / 60) * 1deg))

微信小程序checkbox样式调整

从这样:
在这里插入图片描述
改成这样:
在这里插入图片描述

<label class="checkbox">
  <checkbox value="cb" checked="true" color="#26B888"/>
</label>
// 默认样式
checkbox .wx-checkbox-input {
  width: 32rpx;
  height: 32rpx;
  background-color: transparent;
}

// 选中的样式
checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  color: #fff;
  background-color: #26B888; // 选中后的背景色
}

// 选中 ✓ 的样式
.wx-checkbox-input-checked::before {
  color: #fff; //  ✓ 的颜色
}

交互问题

动态修改页面标题

在这里插入图片描述

created() {
   console.log('dynamicTitle', this.dynamicTitle);
   uni.setNavigationBarTitle({
     title: this.dynamicTitle,
     success: () => {
       console.log('修改标题成功')
     },
     fail: () => {
       console.log('修改标题失败')
     },
     complete: () => {
       console.log('修改标题结束')
     },
   })
 }

动态渲染页面的title:
传参:
在这里插入图片描述
获取动态设置:
在这里插入图片描述
也可以直接设置:
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/183067.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringDataJpa set()方法自动保存失效

问题描述&#xff1a;springdatajpa支持直接操作对象设置属性进行更新数据库记录的方式&#xff0c;正常情况下&#xff0c;get()得到的对象直接进行set后&#xff0c;即使不进行save操作&#xff0c;也将自动更新数据记录&#xff0c;将改动持久化到数据库中&#xff0c;但这里…

20230126使AIO-3568J开发板在原厂Android11下跑起来

20230126使AIO-3568J开发板在原厂Android11下跑起来 2023/1/26 18:22 1、前提 2、修改dts设备树 3、适配板子的dts 4、&#xff08;修改uboot&#xff09;编译系统烧入固件验证 前提 因源码是直接使用原厂的SDK&#xff0c;没有使用firefly配套的SDK源码&#xff0c;所以手上这…

Linux安装mongodb企业版集群(分片集群)

目录 一、mongodb分片集群三种角色 二、安装 1、准备工作 2、安装 configsvr配置 router配置 shard配置 三、测试 四、整合Springboot 一、mongodb分片集群三种角色 router角色&#xff1a; mongodb的路由&#xff0c;提供入口&#xff0c;使得分片集群对外透明&…

【目标检测论文解读复现NO.27】基于改进YOLOv5的螺纹钢表面缺陷检测

前言此前出了目标改进算法专栏&#xff0c;但是对于应用于什么场景&#xff0c;需要什么改进方法对应与自己的应用场景有效果&#xff0c;并且多少改进点能发什么水平的文章&#xff0c;为解决大家的困惑&#xff0c;此系列文章旨在给大家解读最新目标检测算法论文&#xff0c;…

【工程化之路】Node require 正解

require 实现原理 流程概述 步骤1&#xff1a;尝试执行代码require("./1"). 开始调用方法require.步骤2&#xff1a;此时会得到filename&#xff0c;根据filename 会判断缓存中是否已经加载模块&#xff0c;如果加载完毕直接返回&#xff0c;反之继续执行步骤3&…

python图像处理(laplacian算子)

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】 和之前的prewitt算子、sobel算子不同,laplacian算子更适合检测一些孤立点、短线段的边缘。因此,它对噪声比较敏感,输入的图像一定要做好噪声的处理工作。同时,laplacian算子设计…

Leetcode 03. 无重复字符的最长子串 [C语言]

目录题目思路1代码1结果1思路2代码2结果2该文章只是用于记录考研复试刷题题目 Leetcode 03: 给定一个字符串 s &#xff0c;请你找出其中不含有重复字符的 最长子串 的长度。 示例 1: 输入: s “abcabcbb” 输出: 3 解释: 因为无重复字符的最长子串是 “abc”&#xff0c;所…

尚医通-OAuth2-微信登录接口开发(三十一)

目录&#xff1a; &#xff08;1&#xff09;微信登录-OAuth2介绍 &#xff08;2&#xff09;前台用户系统-微信登录-准备工作 &#xff08;3&#xff09;微信登录-生成微信二维码-接口开发 &#xff08;4&#xff09;微信登录-生成验证码-前端整合 &#xff08;5&#xf…

Telerik DevCraft Ultimate R1 2023

Telerik DevCraft Ultimate R1 2023 Kendo UI R1 2023-添加新的Chip和ChipList组件。 KendoReact R1 2023&#xff08;v5.11.0&#xff09;-新的PDFViewer组件允许用户直接在应用程序中查看PDF文档。 Telerik JustLock R1 2023-Visual Studio快速操作菜单现在可以在创建通用…

蓝桥杯重点(C/C++)(随时更新,更新时间:2023.1.29)

点关注不迷路&#xff0c;欢迎推荐给更多人 目录 1 技巧 1.1 取消同步&#xff08;节约时间&#xff0c;甚至能多骗点分&#xff0c;最好每个程序都写上&#xff09; 1.2 万能库&#xff08;可能会耽误编译时间&#xff0c;但是省脑子&#xff09; 1.3 蓝桥杯return 0…

【数据库-通用知识系列-01】数据库规范化设计之范式,让数据库表看起来更专业

我们在设计数据库时考虑的因素包括读取性能&#xff0c;数据一致性&#xff0c;数据冗余度&#xff0c;可扩展性等&#xff0c;好好学习数据库规范化的知识&#xff0c;设计的数据库表看起来才专业。 范式一览 “键”理解&#xff1a; 超键&#xff1a;在关系中能唯一标识元组…

送什么礼物给小学生比较有纪念意义?适合送小学生的小礼物

送给小学生的礼物哪种比较有意义呢&#xff1f;送给学生的礼物&#xff0c;基本上是对学习有所帮助的&#xff0c;但是像送钢笔、练习册这些&#xff0c;有一部分学生是抗拒的&#xff0c;作为大人就是希望对视力、对成长有用的东西&#xff0c;我认为保护视力是现在许多家庭的…

isNotEmpty() 和 isNotBlank() 的区别,字符串判空, StringUtils工具包 StringUtil工具类,isEmpty() 和 isBlank() 的区别

目录1.StringUtils 和 StringUtilStringUtils 的依赖&#xff1a;StringUtils 的用法&#xff1a;StringUtil 工具类2. isNotEmpty() 和 isNotBlank()1.StringUtils 和 StringUtil 注&#xff1a;StringUtils 和 StringUtil 的区别&#xff08;StringUtil为自定义工具类&#…

以表达式作为template参数

目录 一.template参数的分类&#xff1a; 二.非类型参数与默认参数值一起使用 三.应用 一.template参数的分类&#xff1a; ①.某种类型&#xff1a; template<typename T>; ②.表达式(非类型)&#xff1a; template<int length,int position>; 其中length…

Liunx中shell命令行和权限的理解

文章目录前言1.shell外壳的理解2.关于权限理解1.Linux下的用户2.角色划分3.文件和目录的权限3.粘滞位3.总结前言 Linux中的操作都是通过在命令行上敲指令来实现的&#xff0c;本文将简单的介绍Linux中的外壳程序shell以及浅谈一下对Linux中的权限理解。 1.shell外壳的理解 Lin…

微信小程序开发(一)

1. 微信小程序的开发流程 2. 注册小程序 小程序注册页&#xff1a;https://mp.weixin.qq.com/wxopen/waregister?actionstep1 如已注册&#xff0c;直接登录 小程序后台 https://mp.weixin.qq.com/ 即可。 在小程序后台的 【开发管理】→ 【开发设置】下可以查看AppID&…

算法训练营DAY45|322. 零钱兑换、279.完全平方数

两道题思路上有相似之处&#xff0c;都是求得最少的种类方法&#xff0c;也就是说在完全背包里给定容量时&#xff0c;用最少的物品去装满背包。它和用最多的方法去装满背包也有一些相似&#xff0c;也就是说两者实际上是互通的。 322. 零钱兑换 - 力扣&#xff08;LeetCode&a…

HTML零散知识

1、代码规范与思路 参考凹凸实验室代码规范&#xff1a;Aotu.io - 前端代码规范 CSS编写顺序的思路 先确定盒子本身是如何布局 position: absolutefloat: left/rightdisplay: flex 盒子的特性和可见性 display: block/inline-block/inline/nonevisibility/opacity 盒子模型…

【Pytorch项目实战】之生成式模型:DeepDream、风格迁移、图像修复

文章目录生成式模型&#xff08;算法一&#xff09;深度梦境&#xff08;DeepDream&#xff09;&#xff08;算法二&#xff09;风格迁移&#xff08;Style Transfer&#xff09;&#xff08;算法三&#xff09;图像修复&#xff08;Image Inpainting&#xff09;&#xff08;一…

(13)工业界推荐系统-小红书推荐场景及内部实践【用户行为序列建模】

&#xff08;1&#xff09;工业界推荐系统-小红书推荐场景及内部实践【业务指标、链路、ItemCF】 &#xff08;2&#xff09;工业界推荐系统-小红书推荐场景及内部实践【UserCF、离线特征处理】 &#xff08;3&#xff09;工业界推荐系统-小红书推荐场景及内部实践【矩阵补充、…