vue2 获取不到对象的属性值

clipboard.png

<template>
  <div></div>
</template>
<script>
  import Vue from 'vue'
  import { mapMutations } from 'vuex'
  import { mapGetters } from 'vuex'
  import { mapActions } from 'vuex'
  import wx from 'weixin-js-sdk';
  export default {
    props:{
      detail : Object
    },
    data() {
      return {
        wxFile:{
          title : '',
          desc  : '',
          link  : '',
          imgUrl: 'https://vuejs.org/images/logo.png',
        }
      }
    },
    mounted() {
      var self = this;
      self.$store.dispatch('actWx',{
        url: window.location.href.split('#')[0],//notice:参与签名的url不能带#号后的部分
        isNeedWechatJsInfo: true
      });
    },
    methods: {
      initWx(jsSdkUiPackage) {
        var self = this;
        var jsApiList = [
            'checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'onMenuShareQZone'
        ];
        var wxConfig = {
            debug: true,
            appId: jsSdkUiPackage.appId,
            timestamp: jsSdkUiPackage.timestamp,
            nonceStr: jsSdkUiPackage.nonceStr,
            signature: jsSdkUiPackage.signature,
            jsApiList: jsApiList
        };
        // ReSharper disable once UseOfImplicitGlobalInFunctionScope
        wx.config(wxConfig);
        // ReSharper disable once UseOfImplicitGlobalInFunctionScope
        wx.error(function (res) {
            //show_notice('微信配置有误' + JSON.stringify(res),3);
        });
        // ReSharper disable once UseOfImplicitGlobalInFunctionScope
        wx.ready(function () {
            // ReSharper disable once UseOfImplicitGlobalInFunctionScope
            //分享到微信
            console.log(self.wxFile);
            console.log(self.wxFile.title);
            wx.onMenuShareAppMessage({
                title: self.wxFile.title,
                desc: self.wxFile.desc,
                link: self.wxFile.link,
                imgUrl: self.wxFile.imgUrl,
                trigger: function (res) {
                },
                success: function (res) {
                    //show_notice("分享成功",1);
                },
                cancel: function (res) {
                },
                fail: function (res) {
                    //show_notice("分享失败",1);
                }
            });
            //分享到朋友圈
            wx.onMenuShareTimeline({
                title: self.wxFile.title,
                desc: self.wxFile.desc,
                link: self.wxFile.link,
                imgUrl: self.wxFile.imgUrl,
                trigger: function (res) {
                },
                success: function (res) {
                  console.log('分享成功');
                    //show_notice("分享成功",1);
                },
                cancel: function (res) {
                },
                fail: function (res) {
                   console.log('分享失败');
                    //show_notice("分享失败",1);
                }
            });
            // ReSharper disable once UseOfImplicitGlobalInFunctionScope
            //分享到QQ
            wx.onMenuShareQQ({
                title: self.wxFile.title,
                desc: self.wxFile.desc,
                link: self.wxFile.link,
                imgUrl: self.wxFile.imgUrl,
                trigger: function (res) {
                },
                complete: function (res) {
                },
                success: function (res) {
                    //show_notice("分享成功",1);
                },
                cancel: function (res) {
                },
                fail: function (res) {
                    //show_notice("分享失败",1);
                }
            });
            // ReSharper disable once UseOfImplicitGlobalInFunctionScope
            //分享到微博
            wx.onMenuShareWeibo({
                title: self.wxFile.title,
                desc: self.wxFile.desc,
                link: self.wxFile.link,
                imgUrl: self.wxFile.imgUrl,
                trigger: function (res) {
                },
                complete: function (res) {
                },
                success: function (res) {
                    //show_notice("分享成功",1);
                },
                cancel: function (res) {
                },
                fail: function (res) {
                    //show_notice("分享失败",1);
                }
            });
            // ReSharper disable once UseOfImplicitGlobalInFunctionScope
            //分享到QQ空间
            wx.onMenuShareQZone({
                title: self.wxFile.title,
                desc: self.wxFile.desc,
                link: self.wxFile.link,
                imgUrl: self.wxFile.imgUrl,
                trigger: function (res) {
                },
                complete: function (res) {
                },
                success: function (res) {
                    //show_notice("分享成功",1);
                },
                cancel: function (res) {
                },
                fail: function (res) {
                   //show_notice("分享失败",1);
                }
            });
        });
      },
    },
    computed: {
      ...mapGetters({
        wxShare: 'getWx',
      }),
    },
    watch:{
      wxShare(res){
        var self = this;
        var jsSdkUiPackage = res.jsSdkUiPackage;
        if (jsSdkUiPackage && jsSdkUiPackage.appId) {
          self.initWx(jsSdkUiPackage);
        }
      },
      detail(res){
        var self = this;
        //self.wxFile.title = res.title || res.name;
        self.wxFile.desc = res.content;
        self.wxFile.link = window.location.href.split('#')[0];
        self.$set(self.wxFile,'title',res.title || res.name);
      },
      $route (to, from) {
        if(to.path.includes('detail') || to.path.includes('mpDetail')){
          var self = this;
          self.$store.dispatch('actWx',{
            url: window.location.href.split('#')[0],//notice:参与签名的url不能带#号后的部分
            isNeedWechatJsInfo: true
          });
        }
      }
    },
    components: {
    }
  }
</script>
<style lang="scss" scoped>

</style>
阅读 11.5k
2 个回答
let json = JSON.stringify(this.question)
let jsonObj = JSON.parse(json)    
this.shortAnswer = jsonObj.answer;

对象有值 但是 obj.xxx 拿不到值, 转换成为jsonObject 然后在.xxx 就能拿到了。

图片描述

如图所示

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题