【无标题】

11月10号

1、uni-app隐藏H5的头部导航栏page-head的两种方式

  • 使用uni-app生成页面时,会发现默认生成的页面是带了导航栏

     

  • 如果我们想隐藏这个导航栏,可以用如下方式:

    1. 如果所有页面都不需要这个导航栏了,可以在App.vue的公共样式代码中添加

      • /* #ifdef H5 */ 
          uni-page-head { display: none; } 
          /* #endif */
    2. .如果只是当前页面不需要,可以在pages.json中添加代码

      • 将navigationStyle设置为custom是指自定义导航栏,系统会关闭默认的原生导航栏

       

2、uniapp路由跳转

  1. 关于跳转目标为tabbar页面 不生效的问题

  2. 一般情况下我们使用uni开发微信小程序和App时,默认登录页(非tabbar页面)登录成功后才会进入到首页(tabbar页面);

    1.  uni.navigateTo({
              url : 'pages/home/home',
              success(res) {
                console.log(res);
                  },
              fail(err) {
                console.log(err);
               }
          });

    2. 此方式来进行跳转是无法跳转的

  3. 如果想跳转到tabbar页面,就要用下面的方法

    1.  uni.switchTab({
                  url: "/pages/home/home",
                  success(res) {
                      console.log(res);
                  },
                  fail(err) {
                      console.log(err);
                  }
          })

3、Content-Type的格式.

3.1、在HTTP协议消息头中,使用Content-Type来表示媒体类型信息

  • 格式

    • Content-Type:type/subtype ;parameter

      • type:主类型,任意的字符串,如text,如果是号代表所有;

      • subtype:子类型,任意的字符串,如html,如果是号代表所有,用“/”与主类型隔开;

      • parameter:可选参数,如charset,boundary等。

    • 例如:

      • Content-Type: text/html;

      • Content-Type: application/json;charset:utf-8;

        • 现在绝大部分的请求都会以json形式进行传输,post会将序列化后的json字符串直接塞进请求体中。

      • Content-Type: application/x-www-form-urlencoded;charset:utf-8;

        • 这是浏览器原生的form表单类型,或者说是表单默认的类型。

需求一

  1. 供应链系统,除登录注册相关流程接口,其他所有接口需在请求头(headers)中携带APISC-AuthToken作为身份令牌,来进行身份的识别和验证.

  2. 所有验证码提交接口,需在请求头(headers)中携带VC-Token作为验证码令牌,来进行验证码有效性和正确性的验证

  3. 实现

    1. 首先我在全局 untils.js中封装了Ajax请求,先拿到token(验证码的),在做判断

       

       

需求二之上传文件

  1. 这里用到uniappuni.chooseImageuni.uploadFile我这里判断比较多 是因为我的html页面写复杂了

    1. 第一布你需要将这个图片给后端传递过去,第二布后端会给你返回来一个http的图片地址,

      upload() {
                      var that = this;
                      console.log(11);
                      // 获取token
                      var APISC_AuthToken = uni.getStorageSync('APISC-AuthToken')
                      console.log(APISC_AuthToken);
                      uni.chooseImage({
                          count: 1, //count: 6, //默认9
                          sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
                          sourceType: ['album', 'camera'], //从相册选择
                          success: (chooseImageRes) => {
                              const tempFilePaths = chooseImageRes.tempFilePaths;
                              // 拿到图片
                              console.log(tempFilePaths);
                              uni.uploadFile({
                                  url: 'https://api.sc.ngwh.net.cn/app_upload/uploadFile', //仅为示例,非真实的接口地址
                                  filePath: tempFilePaths[0],
                                  name: 'file',
                                  formData: {
                                      'user': 'test'
                                  },
                                  // 请求头
                                  header: {
                                      'APISC-AuthToken': APISC_AuthToken,
                                  },
                                  success: (uploadFileRes) => {
                                      console.log(uploadFileRes.data);
                                      let files = JSON.parse(uploadFileRes.data);
                                      if (files.code == 200) {
                                          that.times++
                                          console.log(that.times)
                                          if (that.times == 1) {
                                              that.types = false
                                              that.imagSrc = files.url
                                              console.log(files.url)
                                          }
                                          if (that.times == 2) {
                                              that.types1 = false
                                              that.imagSrc1 = files.url
                                              console.log(files.url)
                                          }
                                          if (that.times == 3) {
                                              that.types2 = false
                                              that.imagSrc2 = files.url
                                          }
                                          if (that.times == 4) {
                                              that.types3 = false
                                              that.imagSrc3 = files.url
                                          }
                                          if (that.times == 5) {
                                              that.types4 = false
                                              that.imagSrc4 = files.url
                                          }
                                          if (that.times == 6) {
                                              that.types5 = false
                                              that.imagSrc5 = files.url
                                          }
                                          if (that.times == 7) {
                                              that.types6 = false
                                              that.imagSrc6 = files.url
                                          }
                                      }
                                  }
                              });
                          }
                      });
                  }

     

需求三之传值

  1. 数据是一个三级分类的数据,跳转分类显示一二级页面,点击二级页面跳转三级,再回显到分类页面

  2. 在data里面定义一个空数组list:[]

  3. 在一二级页面,先获取数据,记得onLoad

    1. onLoad(){
          this.getlist()
      },
      methods:{
          //获取数据
      getlist(){
          this.$utils.ajax('/app_commodity/getCategory',{}).then((res)=>{
                          console.log(res)
                          if(res.code == 200){
                              this.list = res.data
                          }
                      })
                  }
      }

    2. 页面渲染

      1. <!-- 分类列表 -->
        <view class="lists">
            <!-- 分类名称 -->
            <view v-for="(item) in list" v-bind:key="item.id">
                <view class="list-title" >{{ item.name }}</view>
                    <!-- 二级 遍历一级的儿子-->
                    <view class="list-content">
                        <view class="value" v-for="(liser) in item.son" v-bind:key="liser.id">
                        <view class="ss" :class="{activer:selected[liser.id]==true}" @click="actinx(liser, liser.id)">
                                        {{ liser.name }}
                                    </view>
                                </view>
                            </view>
                        </view>
                    </view>

       

  4. 从二级页面传值到三级页面

    1. 点击下一步跳转把数据传过去

      1. // 下一步跳转
                Level(){
                        let that=this;
                        uni.navigateTo({
                            url:'/pages/categorizelevel/categorizelevel',
                            success:function(res){
                                console.log(that.obj)
                                res.eventChannel.emit('setObj',{data:that.obj})
                            }
                        })
                    },

    2. 三级页面接收数据

      1.  onLoad: function(option) {
                    let that=this;
                  const eventChannel= this.getOpenerEventChannel();
                  eventChannel.on('setObj',function(data){
                      console.log(data);
                      that.list = data.data
                  })

       

    3. 点击三级分类,回显在分类页面

      1. // 这里是function 注意this指向的问题
        onLoad() {
                    let that = this
                    uni.$on('getCategoryID',function(data,value){
                        that.info.categoryID = value // 赋值给分类
                        this.idrestart = data
                        console.log(data)
                        that.idrestart = data
                    })
                    this.getlable()
                },

      2.  

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值