vue实现微博关注,不显示问题处理,wb:follow-button

226 阅读1分钟

vue实现微博关注,不显示问题处理

公司要实现由前端页面可以直接点微博关注的功能,看了官方的文档,只有3句话,看似很简单的一个功能

wecom-temp-784488cfe82175a4d720ab80aba90df6.png

-   看起来超简单,emm.....,然后立马实践,由于是vue项目,可能会有一点区别

    -   首先在public目录下的index.html文件里将上图的第一,二步骤加上 
    

wecom-temp-db8306000bfb0e22a20e5a9f29183f87.png

    -   然后在组件里将第三步加上 
    

wecom-temp-048154f7ca4fe94ace505941ba551a5d.png - 看来就这样大功告成了,是吗?并不是,页面上空空如也

wecom-temp-32b109d964ca673f55cf82dad8ec37aa.png - 纠结了好久,网上也没有相关的文章,于是,自己先测了一下在html页面是否能显示

```
<!DOCTYPE html>
<html xmlns:wb="http://open.weibo.com/wb" lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://tjs.sjs.sinajs.cn/open/api/js/wb.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
    <div>
        <wb:follow-button uid="7617000165" type="red_1" width="67" height="24"></wb:follow-button>
    </div>
</body>
</html>
```

-   打开页面,发现出来了,并且发现这个组件下生成了一个iframe标签 

wecom-temp-431be3e7925152af86d993e04d9543f2.png - 截止到现在,怀疑是vue将这个微博的关注组件的事件给屏蔽掉了,想了一下,这个微博关注组件就是将这个标签里内嵌了一个iframe标签,由于时间限制,就不多做研究,先实现功能,在vue里直接将这个iframe复制过来

```
<template>
  <div>
    <iframe src="http://widget.weibo.com/relationship/followbutton.php?btn=red&amp;style=1&amp;uid=7617000165&amp;width=67&amp;height=24&amp;language=zh_cn" width="67" height="24" frameborder="0" scrolling="no" marginheight="0"></iframe>
  </div>
</template>
```

-   效果实现,但是,注意:本地开发是http,生产环境如果是https需要将iframe里的地址也变成https,要不然还是会报错

  

wecom-temp-e2b002cff8afa64869eafc5945f61a8d.png