vue实现微博关注,不显示问题处理
公司要实现由前端页面可以直接点微博关注的功能,看了官方的文档,只有3句话,看似很简单的一个功能
- 看起来超简单,emm.....,然后立马实践,由于是vue项目,可能会有一点区别
- 首先在public目录下的index.html文件里将上图的第一,二步骤加上
- 然后在组件里将第三步加上
- 看来就这样大功告成了,是吗?并不是,页面上空空如也
- 纠结了好久,网上也没有相关的文章,于是,自己先测了一下在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标签
- 截止到现在,怀疑是vue将这个微博的关注组件的事件给屏蔽掉了,想了一下,这个微博关注组件就是将这个标签里内嵌了一个iframe标签,由于时间限制,就不多做研究,先实现功能,在vue里直接将这个iframe复制过来
```
<template>
<div>
<iframe src="http://widget.weibo.com/relationship/followbutton.php?btn=red&style=1&uid=7617000165&width=67&height=24&language=zh_cn" width="67" height="24" frameborder="0" scrolling="no" marginheight="0"></iframe>
</div>
</template>
```
- 效果实现,但是,注意:本地开发是http,生产环境如果是https需要将iframe里的地址也变成https,要不然还是会报错