欢迎光临,了解微信小程序开发,就上易用通!

实例教程:使用wxParse解析html,小程序登录

发布:2017-12-01 15:03浏览: 来源:网络 作者:tianshu

一:小程序使用wxParse解析html首先去https://github.com/icindy/wxParse下载wxParse,只拷贝wxParse文件夹即可。1、引入wxss@import "../wxParse/wxParse.wxss";2、引入wxmlimport s ...

 
 
 

 

 

 

一:小程序使用wxParse解析html

首先去 

https://github.com/icindy/wxParse

 下载wxParse,只拷贝wxParse文件夹即可。

 

1、引入wxss

 

		
  1. @import "../wxParse/wxParse.wxss";

2、引入wxml

 

		
  1. <import src="../wxParse/wxParse.wxml"/>
  2.  
  3. <view class="wxParse">
  4.  
  5. <template is="wxParse" data="{{wxParseData:article_content.nodes}}"/>
  6.  
  7. </view>

3、引入js并加载数据

 

		
  1. var app = getApp();
  2. var WxParse = require('../wxParse/wxParse.js');
  3. Page({
  4. data: {
  5. motto: 'jxcat',
  6. serverUrl: app.globalData.ajaxUrl,
  7. baseUrl: app.globalData.baseUrl,
  8. title: "文章详情",
  9. article_title: "",
  10. article_content: "",
  11. },
  12.  
  13.  
  14.  
  15.  
  16. onLoad: function (options) {
  17. var that = this
  18. var result
  19. //serverUrl = app.globalData.ajaxUrl
  20. wx.request({
  21. url: app.globalData.ajaxUrl,
  22. data: {
  23. m: 'api',
  24. c: 'article' ,
  25. a: 'info',
  26. aid: options.aid
  27. },
  28. header: {
  29. 'content-type': 'application/json'
  30. },
  31. success: function(res) {
  32. that.setData({
  33. article_title:res.data.article_title,
  34. article_content:WxParse.wxParse('article_content', 'html', res.data.article_content, that, 5)
  35. })
  36. }
  37. })
  38. //request
  39. }
  40. })
 

二:小程序开发之登录

小程序js:

 

		
  1. //app.js
  2. App({
  3. onLaunch: function () {
  4. //调用API从本地缓存中获取数据
  5. var logs = wx.getStorageSync('logs') || []
  6. logs.unshift(Date.now())
  7. wx.setStorageSync('logs', logs)
  8. wx.login({
  9. success: function(res) {
  10. if (res.code) {
  11. //发起网络请求
  12. wx.getUserInfo({
  13. success: function(ures) {
  14. var userInfo = ures.userInfo
  15. var nickName = userInfo.nickName
  16. var avatarUrl = userInfo.avatarUrl
  17. var gender = userInfo.gender //性别 0:未知、1:男、2:女
  18. var province = userInfo.province
  19. var city = userInfo.city
  20. var country = userInfo.country
  21. wx.request({
  22. url: 'https://m.xxx.com/index.PHP',
  23. data: {
  24. m: 'api',
  25. c: 'wechat' ,
  26. a: 'xcx_do_auth',
  27. code: res.code,
  28. rawData: ures.rawData,
  29. encryptData: ures.encryptData,
  30. encryptedData: ures.encryptedData,
  31. iv: ures.iv,
  32. signature: ures.signature
  33. },
  34. header: {
  35. "Content-Type": "application/x-www-form-urlencoded"
  36. },
  37. success: function(lres) {
  38. console.log(lres.data)
  39. }
  40. })
  41. //request
  42. }
  43. })
  44. //getUserInfo
  45. } else {
  46. console.log('获取用户登录态失败!' + res.errMsg)
  47. }
  48. //login
  49. }
  50. });
  51. wx.checkSession({
  52. success: function(){
  53. //登录态未过期
  54. },
  55. fail: function(){
  56. //登录态过期
  57. wx.login()
  58. }
  59. });
  60. },
  61.  
  62. globalData:{
  63. userInfo:null,
  64. ajaxUrl: "https://m.xxx.com/index.php",
  65. baseUrl: "https://www.xxx.com/",





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。