微信公众号链接处理问题

最近微信公众号有做一个功能,包含列表(图片,标题,介绍),列表的每一项点进去是详情(是微信公众号里面的一篇文章链接)

类似有 https://mp.weixin.qq.com 前缀的,然后调试时,手机端打开无法显示,这是微信的机制,所以需要进行转化,

可以利用 http://cors-anywhere.herokuapp.com 这个网址做一个跨域请求处理,就是将我需要的微信文章地址,转换成HTML代码返回

 

<div class="container">
      <iframe v-if="isOutUrl" class="iframe" :src="activityUrl" frameborder="0" scrolling="auto"></iframe>
      <div v-else  v-html="activityUrl"></div>
</div>
import axios from 'axios'

  

export default {
  data() {
    return {
      activityId: this.$route.query.activityId,
      activityUrl: '',
      isOutUrl: false,
      activityInfo: {}
    }
  },
  mounted() {
    this._getActivityUrl()
  },
  methods: {
    _getActivityUrl() {
      getActivityUrl(this.activityId).then(res => {
        this.activityInfo = res.datas;
        let url = res.datas.activityUrl
        let head = url.slice(0, 24);
        // 是微信公众号文章
        if (head == 'https://mp.weixin.qq.com') {
          this.getURL(url);
        } else {// 是其它网址直接使用
          this.isOutUrl = true
          this.activityUrl = url;
        }
      })
    },
    getURL(url) {
      let http = (window.location.protocol === 'http:' ? 'http:' : 'https:');
      let realurl = http + '//cors-anywhere.herokuapp.com/' + url;
      axios.get(realurl).then(res=>{
        this.activityUrl = res.data;
      },rej=>{
        console.log(rej)
      })
    }
}

  

转载于:https://www.cnblogs.com/wangdashi/p/11496283.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值