Vue页面分享QQ\QQ空间\微博\微信

1、封装js代码:share.js文件

// share.js
// url - 需要分享的页面地址(当前页面地址)
// title - 分享的标题(文章标题)

// QQ空间
export function toQQzone(url, title) {
	url = encodeURIComponent(url)
	title = encodeURIComponent(title)
	window.open(
		`https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=${url}&title=${title}&desc=${title}&summary=${title}&site=${url}`
	)
}

//QQ
export function toQQ(url, title) {
	url = encodeURIComponent(url)
	title = encodeURIComponent(title)
	window.open(
		`https://connect.qq.com/widget/shareqq/index.html?url=${url}&title=${title}&source=${url}&desc=${title}&pics=`)
}

//微博
export function toWeibo(url, title) {
	url = encodeURIComponent(url)
	title = encodeURIComponent(title)
	window.open(`https://service.weibo.com/share/share.php?url=${url}&title=${title}&pic=&appkey=&sudaref=`)
}

// 豆瓣
// export function toDouban(url, title) {
// 	url = encodeURIComponent(url)
// 	title = encodeURIComponent(title)
// 	window.open(`http://www.douban.com/recommend?url=${url}&title=${title}`);
// }

//微信  需要单独写个页面展示二维码,使用微信扫描,点击右上角...分享
export function toWechat(url, title) {
	url = encodeURIComponent(url)
	title = encodeURIComponent(title)
	console.log('share.js', process.env)
	let page = this.$router.resolve({
		name: 'sailSoft',
		query: { newId: newId },
	});
	window.open(page.href, '_blank');
	// window.open(`${process.env.NUXT_ENV_APISERVER}/sharetoWechat?url=${url}&title=${title}`)
}

2、分享页面引入并使用:

<el-button type="primary" size="small" @click="share('QQ')">分享至QQ</el-button>
<el-button type="primary" size="small" @click="share('QQzone')">分享至QQ空间</el-button>
<el-button type="primary" size="small" @click="share('WeiBo')">分享至微博</el-button>
<el-button type="primary" size="small" @click="share('WeiXin')">分享至微信</el-button>
import {
		toQQzone,
		toQQ,
		toWeibo,
		toWechat,
		toDouban
	} from '@/utils/share.js'
share(type) {
	const url = 'https://blog.csdn.net/2201_75870706'
	const title = '章小鱼分享啦!!!!'
	switch (type) {
		case 'QQ':
		    toQQ(url, title);
			break;
		case 'QQzone':
			toQQzone(url, title);
			break;
		case 'WeiBo':
			toWeibo(url, title);
			break;
		case 'WeiXin':
			toWechat(url, title);
			break;
		default:
			this.$message.error('出错了!')
			break;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值