国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 熱點(diǎn) > 微信 > 正文

vue實(shí)現(xiàn)微信分享朋友圈,發(fā)送朋友的示例講解

2024-07-22 01:17:13
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

首先下載微信jssdk引入項(xiàng)目中,這里我就不說(shuō)怎么去安裝了,如果不會(huì)的可以看一下npm教程和es6的教程。

第一步,引入微信jssdk,此處我是通過(guò)下載微信jssdk,然后用webpack引入進(jìn)項(xiàng)目的。

第二步,獲取詳情數(shù)據(jù),渲染頁(yè)面。

第三步,獲取詳情數(shù)據(jù)成功后再獲取微信簽名,token等配置信息。

第四步,通過(guò)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">簡(jiǎn)介</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, // 開(kāi)啟調(diào)試模式,調(diào)用的所有api的返回值會(huì)在客戶(hù)端alert出來(lái),若要查看傳入的參數(shù),可以在pc端打開(kāi),參數(shù)信息會(huì)通過(guò)log打出,僅在pc端時(shí)才會(huì)打印。  appId: this.appId, // 必填,公眾號(hào)的唯一標(biāo)識(shí)  timestamp: this.timestamp, // 必填,生成簽名的時(shí)間戳  nonceStr: this.nonceStr, // 必填,生成簽名的隨機(jī)串  signature: this.signature, // 必填,簽名,見(jiàn)附錄1  jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] // 必填,需要使用的JS接口列表,所有JS接口列表見(jiàn)附錄2  })  wx.onMenuShareTimeline({  title: this.details.videoTitle, // 分享標(biāo)題  link: url+'#/...', // 分享鏈接,該鏈接域名或路徑必須與當(dāng)前頁(yè)面對(duì)應(yīng)的公眾號(hào)JS安全域名一致  imgUrl: this.details.coverUrl, // 分享圖標(biāo)  success () {   alert('分享朋友圈成功')   // 用戶(hù)確認(rèn)分享后執(zhí)行的回調(diào)函數(shù)  },  cancel () {   // 用戶(hù)取消分享后執(zhí)行的回調(diào)函數(shù)  }  })  wx.onMenuShareAppMessage({  title: this.details.videoTitle, // 分享標(biāo)題  desc: this.details.videoTitle, // 分享描述  link: url+'#/...', // 分享鏈接,該鏈接域名或路徑必須與當(dāng)前頁(yè)面對(duì)應(yīng)的公眾號(hào)JS安全域名一致  imgUrl: this.details.coverUrl, // 分享圖標(biāo)  type: 'video', // 分享類(lèi)型,music、video或link,不填默認(rèn)為link  dataUrl: this.details.videoUrl, // 如果type是music或video,則要提供數(shù)據(jù)鏈接,默認(rèn)為空  success: function () {   alert('分享給朋友成功')   // 用戶(hù)確認(rèn)分享后執(zhí)行的回調(diào)函數(shù)  },  cancel: function () {   // 用戶(hù)取消分享后執(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>            
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 荆州市| 绩溪县| 安远县| 佛教| 九江县| 阳城县| 仁怀市| 深州市| 平昌县| 阿拉善左旗| 托里县| 天峻县| 清新县| 富源县| 宜春市| 托克托县| 涟水县| 阿拉善盟| 嵊泗县| 福海县| 永春县| 临夏市| 黎川县| 拉萨市| 建始县| 甘泉县| 衡水市| 科技| 乐都县| 九龙城区| 离岛区| 揭东县| 康平县| 壤塘县| 宁化县| 日照市| 仪陇县| 仁怀市| 城步| 陵水| 尉犁县|