首页 > 技术文章 > 微信小程序采坑(一)

zhangym118 2018-03-13 10:29 原文

1、微信小程序如何让text内容空格

<text decode="{{true}}" space="{{true}}">&nbsp;&nbsp;</text>

在text标签中一定得加上decode="{{true}}",然后在需要显示空格的地方放&nbsp; 想空几个空格就放几个&nbsp;

 

2、微信小程序路由跳转指定页面

        微信小程序路由跳转,共有三种形式:页面中使用navigator组件做页面链接形式路由跳转,js中可以使用wx.navigateTo--保留当前页面,跳转到应用内的某个页面,wx.redirectTo--关闭当前页面,跳转到应用内的某个页面 wx.navigateBack()--关闭当前页面,回退前一页面。

页面链接。

属性名类型默认值说明
url String   应用内的跳转链接
redirect Boolean false 是否关闭当前页面
hover-class String navigator-hover 指定点击时的样式类,当hover-class="none"时,没有点击态效果

注:navigator-hover默认为{ opacity: 0.7;}, <navigator/>的子节点背景色应为透明色

示例代码:

/** wxss **/
/** 修改默认的navigator点击态 **/
.navigator-hover {
    color:blue;
}
/** 自定义其他点击态样式类 **/
.other-navigator-hover {
    color:red;
}
<!-- sample.wxml -->
<view class="btn-area">
  <navigator url="navigate?title=navigate" hover-class="navigator-hover">跳转到新页面</navigator>
  <navigator url="redirect?title=redirect" redirect hover-class="other-navigator-hover">在当前页打开(关闭了当前页面)</navigator>
</view>
<!-- navigator.wxml -->
<view style="text-align:center"> {{title}} </view>
<view> 点击左上角返回回到之前页面 </view>
<!-- redirect.wxml -->
<view style="text-align:center"> {{title}} </view>
<view> 点击左上角返回回到上级页面 </view>
// redirect.js navigator.js
Page({
  onLoad: function(options) {
    this.setData({
      title: options.title
    })
  }
})

 

wx.navigateTo(OBJECT)

保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以返回到原页面。

OBJECT参数说明:

参数类型必填说明
url String 需要跳转的应用内页面的路径
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

示例代码:

wx.navigateTo({
  url: 'test?id=1'
})

注意:为了不让用户在使用小程序时造成困扰,我们规定页面路径只能是五层,请尽量避免多层级的交互方式。

wx.redirectTo(OBJECT)

关闭当前页面,跳转到应用内的某个页面。

OBJECT参数说明:

参数类型必填说明
url String 需要跳转的应用内页面的路径
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

示例代码:

wx.redirectTo({
  url: 'test?id=1'
})

wx.navigateBack()

关闭当前页面,回退前一页面。

 

3、BarTab没有显示

1,书写,正确书写时tabBar,不要写成tabbar,地球人都知道 
2,当创建新工程时,app.json中Pages配置是这样的 ,,【图1】, 
注意:微信小程序里面的json文件时不能注释的,图中只是给读者看一下该放在哪里而已,,,,不能注释!!! 
3,在一些json文件中,如果是你没有写上的,就必须加上 {} 花括号。 

4,在BarTab中的List属性,里面的index首页配置,一定要放置在第一项,第一项,重要。【图2】图片中的红色标注的位置,尤其要注意呢

 

 

 

 

 

 

推荐阅读