定义数据
发布于 5 年前 作者 cxie 9507 次浏览 来自 问答
3 回复

我要做的是一个页面的分享,页面上有一些数据信息,去掉data哪一行的话 分享出去会提示页面不存在,加上他分享出去后页面可以打开,但是没有携带数据信息。。

//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    addtel:’’,
   // phoneNum: ‘154549865’//测试用的号码,并非真实号码
    addtel1: ‘’,
    addtel2: ‘’,
    addtel3: ‘’,
    addtel4: ‘’,
    addtel5: ‘’,
    addtel6: ‘’,
    addtel7: ‘’,
    addtel8:’’,
  },
  onShow: function () {
    var that = this;
    wx.getStorage({
      key: ‘addTel’,
      success: function (res) {
        console.log(res.data)
        that.setData({
          addtel: res.data
        })
      }
    }),

      wx.getStorage({
        key: ‘addTel1’,
        success: function (res) {
          console.log(res.data)
          that.setData({
            addtel1: res.data
          })
        }
      }),
      wx.getStorage({
        key: ‘addTel2’,
        success: function (res) {
          console.log(res.data)
          that.setData({
            addtel2: res.data
          })
        }
      }),
      wx.getStorage({
        key: ‘addTel3’,
        success: function (res) {
          console.log(res.data)
          that.setData({
            addtel3: res.data
          })
        }
      }),
      wx.getStorage({
        key: ‘addTel4’,
        success: function (res) {
          console.log(res.data)
          that.setData({
            addtel4: res.data
          })
        }
      }),
      wx.getStorage({
        key: ‘addTel5’,
        success: function (res) {
          console.log(res.data)
          that.setData({
            addtel5: res.data
          })
        }
      }),
      wx.getStorage({
        key: ‘addTel6’,
        success: function (res) {
          console.log(res.data)
          that.setData({
            addtel6: res.data
          })
        }
      }),
      wx.getStorage({
        key: ‘addTel7’,
        success: function (res) {
          console.log(res.data)
          that.setData({
            addtel7: res.data
          })
        }
      }),
      wx.getStorage({
        key: ‘addTel8’,
        success: function (res) {
          console.log(res.data)
          that.setData({
            addtel8: res.data
          })
        }
      })

  },

  onReady:function(){
   
  },

//以下是拨打电话及地址地图的代码-----------------------------------------------------------------------
  // 长按号码响应函数
  phoneNumTap: function () {
    var that = this;
    // 提示呼叫号码还是将号码添加到手机通讯录
    wx.showActionSheet({
      itemList: [‘呼叫’, ‘添加联系人’],
      success: function (res) {
        if (res.tapIndex === 0) {
          // 呼叫号码
          wx.makePhoneCall({
            phoneNumber: that.data.addtel,
          })
        } else if (res.tapIndex == 1) {
          // 添加到手机通讯录
          wx.addPhoneContact({
            firstName: ‘test’,//联系人姓名
            mobilePhoneNumber: that.data.addtel,//联系人手机号
          })
        }
      }
    })
  },
 
  phoneNumTapTwo: function () {
    var that = this;
    // 提示呼叫号码还是将号码添加到手机通讯录
    wx.showActionSheet({
      itemList: [‘呼叫’, ‘添加联系人’],
      success: function (res) {
        if (res.tapIndex === 0) {
          // 呼叫号码
          wx.makePhoneCall({
            phoneNumber: that.data.addtel5,
          })
        } else if (res.tapIndex == 1) {
          // 添加到手机通讯录
          wx.addPhoneContact({
            firstName: ‘test’,//联系人姓名
            mobilePhoneNumber: that.data.addtel5,//联系人手机号
          })
        }
      }
    })
  },

  getLocation: function () {
    wx.getLocation({
      type: ‘gcj02’, //返回可以用于wx.openLocation的经纬度
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        var speed = res.speed;
        var accuracy = res.accuracy;
        console.log(latitude);
        console.log(longitude);
        console.log(speed);
        console.log(accuracy);
        wx.openLocation({
          latitude: latitude,
          longitude: longitude,
          name: ‘鑫联必升文化发展有限公司’,
          address: ‘北京市海淀区天秀路10号 农大国际创业园1-418’,
          scale: 28
        })
      }
    })
  },
  //以上是拨打电话及地址地图的代码--------------------------------------------------------------------

  //以下是分享本页面代码--------------------
  onShareAppMessage: function () {
    return {
      title: ‘个人名片信息’,
      desc: ‘自定义分享描述’,
      //path: ‘/page/user?id=123’,
      path: ‘/page/index/index’,
      data: { data }
    }
  }
  //以上是分享本页面代码--------------------
 

})

这是我的代码,小白一个,望大神指点一二  谢谢!

别扯淡了,不能凭空造物,最后一行data这个变量根本就没声明,这是语法常识,最后一行去掉,

页面不存在是因为你路径写错了,/pages/index/index,少个s,

想要传递参数用类似get请求,参数添加在地址url后面,

把data那一行去掉

回到顶部