Moments에서 WeChat 공유를 구현하고 Vue에서 친구를 보내는 방법

亚连
풀어 주다: 2018-06-06 14:22:28
원래의
4160명이 탐색했습니다.

아래에서는 Moments에서 WeChat 공유를 구현하고 친구에게 보내는 Vue의 예를 공유하겠습니다. 이는 좋은 참조 가치가 있으며 모든 사람에게 도움이 되기를 바랍니다.

먼저 WeChat jssdk를 다운로드하여 프로젝트에 도입하세요. 여기서는 설치 방법을 다루지 않겠습니다. 방법을 모르신다면 npm 튜토리얼과 es6 튜토리얼을 살펴보세요.

첫 번째 단계는 WeChat jssdk를 소개하는 것입니다. 여기서는 WeChat jssdk를 다운로드한 다음 webpack을 사용하여 프로젝트에 소개합니다.

두 번째 단계, 상세 데이터를 얻고 페이지를 렌더링합니다.

세 번째 단계, 상세 데이터를 성공적으로 얻은 후 WeChat 서명, 토큰 및 기타 구성 정보를 얻습니다.

네 번째 단계, API를 통해 원하는 기능을 구성하세요

코드:

<template>
 <p class="details">
 <player :videoUrl="details.videoUrl" :coverUrl="details.coverUrl" :videoId="details.videoId"/>
 <p 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>
 </p>
 </p>
</template>
<script>
import player from &#39;@/components/player&#39;
import { videoDtails, getApp } from &#39;@/config/api&#39;
/* eslint-disable no-undef */
export default {
 components: {
 player
 },
 data () {
 return {
  details: {},
  appId: &#39;&#39;,
  signature: &#39;&#39;,
  timestamp: &#39;&#39;,
  nonceStr: &#39;&#39;
 }
 },
 beforeDestroy () {
 document.querySelector(&#39;.htmlTitle&#39;).text = &#39;title&#39;
 },
 mounted () {
 // 获取详情数据<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(&#39;.htmlTitle&#39;).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, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  appId: this.appId, // 必填,公众号的唯一标识
  timestamp: this.timestamp, // 必填,生成签名的时间戳
  nonceStr: this.nonceStr, // 必填,生成签名的随机串
  signature: this.signature, // 必填,签名,见附录1
  jsApiList: [&#39;onMenuShareTimeline&#39;, &#39;onMenuShareAppMessage&#39;] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  })
  wx.onMenuShareTimeline({
  title: this.details.videoTitle, // 分享标题
  link: url+&#39;#/...&#39;, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  imgUrl: this.details.coverUrl, // 分享图标
  success () {
   alert(&#39;分享朋友圈成功&#39;)
   // 用户确认分享后执行的回调函数
  },
  cancel () {
   // 用户取消分享后执行的回调函数
  }
  })
  wx.onMenuShareAppMessage({
  title: this.details.videoTitle, // 分享标题
  desc: this.details.videoTitle, // 分享描述
  link: url+&#39;#/...&#39;, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  imgUrl: this.details.coverUrl, // 分享图标
  type: &#39;video&#39;, // 分享类型,music、video或link,不填默认为link
  dataUrl: this.details.videoUrl, // 如果type是music或video,则要提供数据链接,默认为空
  success: function () {
   alert(&#39;分享给朋友成功&#39;)
   // 用户确认分享后执行的回调函数
  },
  cancel: function () {
   // 用户取消分享后执行的回调函数
  }
  })
 }
 }
}
</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에서 cli의 포괄적인 해석(자세한 튜토리얼)

angularJS에서 라디오를 사용하여 두 개 중 하나의 선택을 구현하는 방법(자세한 튜토리얼)

Angularjs에서 기본 선택 가져오기 라디오 버튼의 값 방식(자세한 튜토리얼)

위 내용은 Moments에서 WeChat 공유를 구현하고 Vue에서 친구를 보내는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!