便捷方法

// 文字超出省略(多行)
overflow: hidden;
word-break: break-all;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;

// 文字超出省略(单行)
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;

// 获取元素高度
let that = this;
setTimeout(() => {
    let query = wx.createSelectorQuery();
    query.select('.box').boundingClientRect(rect=>{
        that.setData({
            height:  rect.height
        });
      }).exec();
}, 100);

// 调取子元素方法
this.selectComponent('.shopping').switch_fun();

// 点击上传图片
upload_image(){
    const that = this;
    wx.showActionSheet({
      itemList: ['从相册中选择', '拍照'],
      itemColor: "#f7982a",
      success: function (res) {
        if (!res.cancel) {
          if (res.tapIndex == 0) {
            that.chooseWxImageShop('album');//从相册中选择
          } else if (res.tapIndex == 1) {
            that.chooseWxImageShop('camera');//手机拍照
          }
        }
      }
    })
  },
  // 选择图片
  chooseWxImageShop: function (type) {
    var that = this;
    // 选择图片api或者拍照
    wx.chooseImage({
      sizeType: ['original', 'compressed'],
      sourceType: [type],
      success: async function (photo) {
        let images = that.data.img;
        let images_load = that.data.show_img;
        photo.tempFilePaths.forEach(ele => {
          const thumb = wx.getFileSystemManager().readFileSync(ele, 'base64');
          images_load.push(thumb);
          images.push(ele);
        });
        that.setData({
          img: images,
          show_img: images_load
        });
      }
    })
  },

// 获取页面参数
let pages = getCurrentPages() // 获取加载的页面
let currentPage = pages[pages.length - 1] // 获取当前页面的对象
let url = currentPage.route // 当前页面url
let options = currentPage.options // 如果要获取url中所带的参数可以查看options

你可能感兴趣的:(便捷方法)