小程序模板网

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

一:小程序使用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/",


易优小程序(企业版)+灵活api+前后代码开源 码云仓库:starfork
本文地址:https://www.eyoucms.com/wxmini/doc/course/17999.html 复制链接 如需定制请联系易优客服咨询:800182392 点击咨询
QQ在线咨询