随笔分类 - taro小程序
摘要:配置服务部分: h5: { devServer: { host: "m.loubei.com", port: 80, open: false, proxy: { '/api/': { target: 'https://api.fczx.com', ws: true, //开启websoket pat
阅读全文
摘要:taro Map组件不兼容H5 地图父组件: import React, { useEffect, useMemo, useRef, useState } from 'react' import Taro, { getCurrentInstance, useReady } from '@tarojs
阅读全文
摘要:首先在index.html文件引入: <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=kM1RFA6AzOnv6lmlc7qyOMhqBILu1pgk"></script> 简单实现地图显示: useReady
阅读全文
摘要:h5使用useRouter导致返回报错TypeError: Cannot read property 'options' of undefined at onUnload 使用taro的getCurrentInstance().router获取参数 / 目标页面获取数据,Class组件: const
阅读全文
摘要:npm install tarojs-router 简单实现: github: https://github.com/lblblong/tarojs-router 创建router配置目录src/router src/router/middleware/author-check.ts import
阅读全文
摘要:MovableView不支持h5,使用onTouchMove实现拖拽 main.tsx import React, { useEffect, useState } from 'react' import Taro from '@tarojs/taro' import { View, Image, T
阅读全文
摘要:# taro $ taro update self # npm npm i -g @tarojs/cli@latest taro update project
阅读全文
摘要:x函数组件 import {useScope} from '@tarojs/taro'const scope=useScope()Taro.createIntersectionObserver(scope)
阅读全文
摘要:封装组件使用,只创建一个对象: import Taro from '@tarojs/taro' class CustomSocket { public socketOpen: boolean = false public socketMsgQueue: string[] = [] private l
阅读全文
摘要:带参数: const pages: any = getCurrentPages() const prevPage: any = pages[pages.length - 2] prevPage.setData({ isSync: true }) Taro.navigateBack({ delta:
阅读全文
摘要:event.ts: import api from '@services/api' import { hasLogin } from '@services/login' import app from '@services/request' import storage from './storag
阅读全文
摘要:定义单个Picker选项组件: import React, { useEffect, useState } from 'react' import { View, PickerView, PickerViewColumn } from '@tarojs/components' import clas
阅读全文
摘要:封装单个picker: import React, { useState } from 'react' import { View, PickerView, PickerViewColumn } from '@tarojs/components' import classnames from 'cl
阅读全文
摘要:时间显示处理方法: // 格式化时间段 const toTimeSolt = (h: number) => { let bt = ''; if (0 <= h && h <= 3) bt = '凌晨'; if (4 <= h && h <= 8) bt = '早上'; if (9 <= h && h
阅读全文
摘要:百度静态地图链接: export const getStaticMap = (lng: number, lat: number, zoom: number = 16) => { return `http://api.map.baidu.com/staticimage?center=${lng},${
阅读全文
摘要:微信小程序的image标签中有个mode属性,使用aspectFill即可 注:image组件默认宽度300px、高度225px mode 有效值: mode 有 13 种模式,其中 4 种是缩放模式,9 种是裁剪模式 mode: 'aspectFit' 的处理模式: const handleLoa
阅读全文
摘要:使用方法: useRef && useImperativeHandle && forwardRef lodash -> isEqual 父组件: import React, { useCallback, useEffect, useMemo, useRef, useState } from 'rea
阅读全文
摘要:父组件调用子组件方法:实现父组件滚动下拉更新分页 子组件注册方法传给父组件: useImperativeHandle(ref, () => ({ innerFn: handleScrollToLower }), [page.totalPage, param.currentPage]) const h
阅读全文
摘要:toggleFolder 里面设置setVideos(videos)不更新,单独设置setFolder更新页面 import React, { useEffect, useState } from 'react' import { useShareAppMessage } from '@tarojs
阅读全文
摘要:当分享按钮在子组件时,子组件不是页面,没有配置pages,所以在子组件设置enableShareAppMessage:true无效 所以父组件设置enableShareAppMessage:true,子组件使用 useShareAppMessage((res) => { console.log("u
阅读全文