vue實(shí)現(xiàn)微信分享朋友圈,發(fā)送朋友的示例講解
首先下載微信jssdk引入項(xiàng)目中,這里我就不說怎么去安裝了,如果不會的可以看一下npm教程和es6的教程。
第一步,引入微信jssdk,此處我是通過下載微信jssdk,然后用webpack引入進(jìn)項(xiàng)目的。
第二步,獲取詳情數(shù)據(jù),渲染頁面。
第三步,獲取詳情數(shù)據(jù)成功后再獲取微信簽名,token等配置信息。
第四步,通過api配置所想要的功能
代碼:
<template>
<div class="details">
<player :videoUrl="details.videoUrl" :coverUrl="details.coverUrl" :videoId="details.videoId"/>
<div class="description">
<span class="label" :style="{backgroundColor: details.videoLabelColor}">{{details.videoLabel}}</span>
<p class="title">{{details.videoTitle}}</p>
<p class="info">
<span>{{details.mtime}}</span>
<i class="iconfont icon--"></i>
{{details.videoPlayTimes}}
</p>
<p class="summary">簡介</p>
<p class="article ql-editor" v-html="details.videoDescription"></p>
</div>
</div>
</template>
<script>
import player from '@/components/player'
import { videoDtails, getApp } from '@/config/api'
/* eslint-disable no-undef */
export default {
components: {
player
},
data () {
return {
details: {},
appId: '',
signature: '',
timestamp: '',
nonceStr: ''
}
},
beforeDestroy () {
document.querySelector('.htmlTitle').text = 'title'
},
mounted () {
// 獲取詳情數(shù)據(jù)<span class="space" style="white-space:pre;display:inline-block;text-indent:2em;line-height:inherit;">let url = window.location.href.split("#")[0]</span>
this.$http.get(this, videoDtails, {videoId: this.$route.query.id}, res => {
this.details = res
document.querySelector('.htmlTitle').text = this.details.videoTitle
this.$http.get(this, getApp, {url: url, refresh: true}, res => {
this.appId = res.appId
this.signature = res.signature
this.timestamp = res.timestamp
this.nonceStr = res.nonceStr
this.shard(url)
})
})
},
methods: {
shard (url) {
wx.config({
debug: true, // 開啟調(diào)試模式,調(diào)用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數(shù),可以在pc端打開,參數(shù)信息會通過log打出,僅在pc端時(shí)才會打印。
appId: this.appId, // 必填,公眾號的唯一標(biāo)識
timestamp: this.timestamp, // 必填,生成簽名的時(shí)間戳
nonceStr: this.nonceStr, // 必填,生成簽名的隨機(jī)串
signature: this.signature, // 必填,簽名,見附錄1
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2
})
wx.onMenuShareTimeline({
title: this.details.videoTitle, // 分享標(biāo)題
link: url+'#/...', // 分享鏈接,該鏈接域名或路徑必須與當(dāng)前頁面對應(yīng)的公眾號JS安全域名一致
imgUrl: this.details.coverUrl, // 分享圖標(biāo)
success () {
alert('分享朋友圈成功')
// 用戶確認(rèn)分享后執(zhí)行的回調(diào)函數(shù)
},
cancel () {
// 用戶取消分享后執(zhí)行的回調(diào)函數(shù)
}
})
wx.onMenuShareAppMessage({
title: this.details.videoTitle, // 分享標(biāo)題
desc: this.details.videoTitle, // 分享描述
link: url+'#/...', // 分享鏈接,該鏈接域名或路徑必須與當(dāng)前頁面對應(yīng)的公眾號JS安全域名一致
imgUrl: this.details.coverUrl, // 分享圖標(biāo)
type: 'video', // 分享類型,music、video或link,不填默認(rèn)為link
dataUrl: this.details.videoUrl, // 如果type是music或video,則要提供數(shù)據(jù)鏈接,默認(rèn)為空
success: function () {
alert('分享給朋友成功')
// 用戶確認(rèn)分享后執(zhí)行的回調(diào)函數(shù)
},
cancel: function () {
// 用戶取消分享后執(zhí)行的回調(diào)函數(shù)
}
})
}
}
}
</script>
<style lang="less" scoped>
.details {
overflow: hidden;
.description {
padding: 10px;
.label {
display: inline-block;
padding:0 10px;
height: 22px;
line-height: 22px;
color: #fff;
font-size: 12px;
text-align: center;
}
.title {
line-height: 30px;
font-size: 18px;
}
.info {
line-height: 26px;
color: #949494;
span {
margin-right: 15px;
}
.iconfont {
font-size: 12px;
}
}
.summary {
margin-top: 20px;
color: #4b4b4b;
font-size: 16px;
}
.article {
margin-top: 10px;
}
}
}
</style>
以上這篇vue實(shí)現(xiàn)微信分享朋友圈,發(fā)送朋友的示例講解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- VueJs單頁應(yīng)用實(shí)現(xiàn)微信網(wǎng)頁授權(quán)及微信分享功能示例
- Vue單頁式應(yīng)用(Hash模式下)實(shí)現(xiàn)微信分享的實(shí)例
- vue微信分享 vue實(shí)現(xiàn)當(dāng)前頁面分享其他頁面
- vue微信分享出來的鏈接點(diǎn)開是首頁問題的解決方法
- Vue項(xiàng)目全局配置微信分享思路詳解
- vue-cli構(gòu)建項(xiàng)目下使用微信分享功能
- vue項(xiàng)目中實(shí)現(xiàn)的微信分享功能示例
- vue實(shí)現(xiàn)微信分享功能
- vue-router history模式下的微信分享小結(jié)
- vue微信分享插件使用方法詳解
相關(guān)文章
一次Vue中computed沒有觸發(fā)的原因以及排查經(jīng)歷
這篇文章主要介紹了一次Vue中computed沒有觸發(fā)的原因以及排查經(jīng)歷,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11
vue項(xiàng)目如何實(shí)現(xiàn)前端預(yù)覽word與pdf格式文件
最近項(xiàng)目中需要在線預(yù)覽WORD文檔,所以給大家總結(jié)下,這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目如何實(shí)現(xiàn)前端預(yù)覽word與pdf格式文件的相關(guān)資料,需要的朋友可以參考下2023-03-03
一篇文章帶你吃透Vue生命周期(結(jié)合案例通俗易懂)
這篇文章主要給大家介紹了關(guān)于如何通過一篇文章帶你吃透Vue生命周期,文章通過結(jié)合案例更加的通俗易懂,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-02-02
Vue封裝Swiper實(shí)現(xiàn)圖片輪播效果
圖片輪播是前端中經(jīng)常需要實(shí)現(xiàn)的一個(gè)功能。最近學(xué)習(xí)Vue.js,就針對Swiper進(jìn)行封裝,實(shí)現(xiàn)一個(gè)簡單的圖片輪播組件。感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧2018-02-02

