当前位置 : 主页 > 编程语言 > 小程序开发 >

微信小程序常见的开发问题汇总

来源:互联网 收集:自由互联 发布时间:2021-08-15
1. coverview 中的强制换行 .wrap{ word-break: break-all; word-wrap:break-word; white-space:pre-line;} 2. IOS 阻止页面弹性橡皮筋效果 // taro 为例import Taro, { Component, Config } from @tarojs/taro;export default class Home

1. coverview 中的强制换行

.wrap{
  word-break: break-all;
  word-wrap:break-word;
  white-space:pre-line;
}

2. IOS 阻止页面弹性橡皮筋效果

// taro 为例
import Taro, { Component, Config } from '@tarojs/taro';

export default class HomePage extends Component {
    config: Config = {
        navigationBarTitleText: '首页',       
        disableScroll: true, // 这一句
    };
}

3. 组件之间的通信方法传递,taro 中需要方法名为 on 开头

container.js

import Child from 'child';

render(){
    return <View>
        <Child onToggle={this.handleToggle.bind(this)}/>
    </View>
}

child.js

handleClick(){
    this.props.onToggle();
}

render(){
    return <View onClick={this.handleClick.bind(this)}>点击测试</View>
}

4. 微信小程序地图

  • 在用户手动缩放地图时,不会自动触发 scale 的变化,如果要将地图缩放到初始大小,scale 值是没有变化的,不会触发页面更新;此时可以略微改变一下 scale 值,加上一个很小的数,如 0.000001
state = {
    scale : 10
}

resetScale(){
    this.setState({
        scale:this.state.scale===10?10.00001:10
    })
}

render(){
    return (
        <Map scale={this.state.scale}/>
    )
}
  • 地图定位不准的问题,尝试使用 gcj02 坐标
Taro.getLocation({
    type:'gcj02' // 这里
})
.then(res=>{
    let { longitude, latitude } = res;
})

推荐教程:《微信小程序》

以上就是微信小程序常见的开发问题汇总的详细内容,更多请关注自由互联其它相关文章!

网友评论