请问 跳转url怎么加入 当前页面id
发布于 5 年前 作者 myi 11198 次浏览 来自 问答

             wx.navigateTo({

               url: “…/detail-huiyuan/detail?aid=当前文章id”,

             })

 请问   上面的当前文章id 要怎么获取呢        

 

const api = require(’…/…/utils/api.js’)
const util = require(’…/…/utils/util.js’)
const { wxPromisify, post } = require(’…/…/utils/promisfn.js’)
var WxParse = require(’…/…/wxParse/wxParse.js’);

Page({
  data: {
    correlationList: [],
    articleId: ‘’,
    title: ‘文章详情’,
    articleInfo: {},
    upArticle: {},
    downArticle: {},
    floorstatus: false, //回到顶部是否存在
  },
  getArticle() {
    var _self = this;
    // 显示加载图标
    wx.showLoading({
      title: ‘玩命加载中’,
    })
    post(api.urls.articleUrl + _self.data.articleId, {}).then(res => {
      // 隐藏加载框
      if (res.data.code == 1) {
        wx.hideLoading();
        var articleFo = res.data.result.body;
        articleFo.pubdate = util.formatTime(articleFo.pubdate, ‘Y-M-D’);
        //富文本解析
        WxParse.wxParse(‘article’, ‘html’, articleFo.body, _self, 5);
        _self.setData({
          articleInfo: articleFo,
          upArticle: res.data.result.updw.up,
          downArticle: res.data.result.updw.dw,
          correlationList: res.data.result.correlation
        })
      } else {
        wx.showToast({
          title: ‘数据获取失败’,
          duration: 2000
        })
      }
    })
  },

  // 获取滚动条当前位置
  onPageScroll: function (e) {
    if (e.scrollTop > 100) {
      this.setData({
        floorstatus: true
      });
    } else {
      this.setData({
        floorstatus: false
      });
    }
  },

  //回到顶部
  goTop: function (e) { // 一键回到顶部
    if (wx.pageScrollTo) {
      wx.pageScrollTo({
        scrollTop: 0
      })
    } else {
      wx.showModal({
        title: ‘提示’,
        content: ‘当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。’
      })
    }
  },

  formSubmit: function (e) {

    if (e.detail.value.zhanghao.length == 0 || e.detail.value.mima.length == 0) {
      wx.showToast({
        title: ‘账户或密码为空!’,
        icon: ‘loading’,
        duration: 1500
      })
      setTimeout(function () {
        wx.hideToast()
      }, 2000)
    } else {
      wx.request({
        url: 'https://xxx.xxxxx/api/denglu.php’,
        method: ‘GET’,
        header: {
          ‘content-type’: ‘application/json’
        },
        data: {
          num: e.detail.value.zhanghao,
          pass: e.detail.value.mima,
          
        },
 
        success: function (res) {
          console.log(res.data);
          console.log(“账号:” + res.data.num + “密码:” + res.data.pass);
          console.log(“输入账号为:” + e.detail.value.zhanghao + “输入密码为:” + e.detail.value.mima);
 
          if (res.data.num == e.detail.value.zhanghao || res.data.pass == e.detail.value.mima) {
            
            //如果输入结果符合查询结果,将要执行的代码(我这里直接跳转了一个页面)
          
              wx.navigateTo({
                url: “…/detail-huiyuan/detail?aid=${item.id}”,
              })
           
       

 

          } else {
            wx.showToast({
              title: ‘账户或密码错误!’,
              icon: ‘loading’,
              duration: 1500
            })
            setTimeout(function () {
              wx.hideToast()
            }, 2000)
          }
        }
      })
    }

  },

  onLoad: function (options) {
    //options 获取传递过来的参数
    var _self = this;
    this.setData({
      articleId: options.aid
    })
    wx.setNavigationBarTitle({
      title: _self.data.title //页面标题为路由参数
    })
    this.getArticle();
  },

})

2 回复

代码是你写的吗?这种问题居然也问的出来

onLoad生命周期里获取

回到顶部