微信分享、vue中select的v-model绑定(监听enter键)、数组对象重组(18/06/22)

333 阅读1分钟

微信分享

 $().ready(function () {
            var title = '标题';
            var desc = '描述:随便输入吧,哈哈哈哈哈哈哈哈哈哈哈。';
            var link = location.href.split('#')[0];
            var imgUrl = 'http://XXXX/img/course/wxshare-mc.png';//自己放线上图片

            $.ajax({
                url: "/wechat/shareconfig/",
                type: "POST",
                cache: false,
                dataType: "json",
                data: { url: link },
                success: function (data) {
                    wx.config(data);
                    wx.ready(function () {

                        // 2. 分享接口
                        // 2.1 监听“分享给朋友”,按钮点击、自定义分享内容及分享结果接口

                        wx.onMenuShareAppMessage({
                            title: title,
                            desc: desc,
                            link: link,
                            imgUrl: imgUrl,
                            trigger: function (res) {

                            },
                            success: function (res) {
                                window.location.href = "https://juejin.cn/user/3386151544554429";
                            },
                            cancel: function (res) {

                            },
                            fail: function (res) {

                            }
                        });



                        // 2.2 监听“分享到朋友圈”按钮点击、自定义分享内容及分享结果接口

                        wx.onMenuShareTimeline({
                            title: title,
                            link: link,
                            imgUrl: imgUrl,
                            trigger: function (res) {

                            },
                            success: function (res) {
                                window.location.href = "https://juejin.cn/user/3386151544554429";
                            },
                            cancel: function (res) {

                            },
                            fail: function (res) {

                            }
                        });

                        //获取“分享到QQ”按钮点击状态及自定义分享内容接口
                        wx.onMenuShareQQ({
                            title: title, // 分享标题
                            desc: desc, // 分享描述
                            link: link, // 分享链接
                            imgUrl: imgUrl, // 分享图标
                            success: function () {
                                // 用户确认分享后执行的回调函数
                            },
                            cancel: function () {
                                // 用户取消分享后执行的回调函数
                            }
                        });



                    });
                },
                error: function (data) {


                }
            });
        });

vue中监听enter事件并且保存select的v-model

 contactSearch(e) {
      const name = this.$refs.input.$el.querySelector("input").value.trim();
      if (name !== "") {
        this.load.contact = true;
        contactApi.getContactList({ name: name }).subscribe(
          data => {
            this.load.contact = false;
            this.contactList = data.contacts;
            console.log(this.contactList);
            for (var i = 0; i < this.contactList.length; i++) {
              console.log(this.newContactList)
              this.newContactList[i]=[];
              this.newContactList[i].companyNamePeople= this.contactList[i].name + "(" +this.contactList[i].company.name +")";
              this.newContactList[i].id=this.contactList[i].id 
            }
            this.member.contactId = name;
          },
          err => {
            this.load.contact = false;
            this.contactList = [];
          }
        );
      } else {
        // this.fetchContactList()
      }
    },

遍历对象数组并取出字段组合成新数组

在data中初始化数组

 data() {
    return {
         contactList: [],
        newContactList: []
    }
  }

接下来对获取的data.contacts进行处理

 this.contactList = data.contacts;
            console.log(this.contactList);
            for (var i = 0; i < this.contactList.length; i++) {
              console.log(this.newContactList)
              this.newContactList[i]=[];
              this.newContactList[i].companyNamePeople= this.contactList[i].name + "(" +this.contactList[i].company.name +")";
              this.newContactList[i].id=this.contactList[i].id 
    }