一:小程序使用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
-
@import "../wxParse/wxParse.wxss";
2、引入wxml
-
<import src="../wxParse/wxParse.wxml"/>
-
<view class="wxParse">
-
<template is="wxParse" data="{{wxParseData:article_content.nodes}}"/>
-
</view>
3、引入js并加载数据
-
var app = getApp();
-
var WxParse = require('../wxParse/wxParse.js');
-
Page({
-
data: {
-
motto: 'jxcat',
-
serverUrl: app.globalData.ajaxUrl,
-
baseUrl: app.globalData.baseUrl,
-
title: "文章详情",
-
article_title: "",
-
article_content: "",
-
},
-
onLoad: function (options) {
-
var that = this
-
var result
-
//serverUrl = app.globalData.ajaxUrl
-
wx.request({
-
url: app.globalData.ajaxUrl,
-
data: {
-
m: 'api',
-
c: 'article' ,
-
a: 'info',
-
aid: options.aid
-
},
-
header: {
-
'content-type': 'application/json'
-
},
-
success: function(res) {
-
that.setData({
-
article_title:res.data.article_title,
-
article_content:WxParse.wxParse('article_content', 'html', res.data.article_content, that, 5)
-
})
-
}
-
})
-
//request
-
}
-
})
二:小程序开发之登录
小程序js:
-
//app.js
-
App({
-
onLaunch: function () {
-
//调用API从本地缓存中获取数据
-
var logs = wx.getStorageSync('logs') || []
-
logs.unshift(Date.now())
-
wx.setStorageSync('logs', logs)
-
wx.login({
-
success: function(res) {
-
if (res.code) {
-
//发起网络请求
-
wx.getUserInfo({
-
success: function(ures) {
-
var userInfo = ures.userInfo
-
var nickName = userInfo.nickName
-
var avatarUrl = userInfo.avatarUrl
-
var gender = userInfo.gender //性别 0:未知、1:男、2:女
-
var province = userInfo.province
-
var city = userInfo.city
-
var country = userInfo.country
-
wx.request({
-
url: 'https://m.xxx.com/index.PHP',
-
data: {
-
m: 'api',
-
c: 'wechat' ,
-
a: 'xcx_do_auth',
-
code: res.code,
-
rawData: ures.rawData,
-
encryptData: ures.encryptData,
-
encryptedData: ures.encryptedData,
-
iv: ures.iv,
-
signature: ures.signature
-
},
-
header: {
-
"Content-Type": "application/x-www-form-urlencoded"
-
},
-
success: function(lres) {
-
console.log(lres.data)
-
}
-
})
-
//request
-
}
-
})
-
//getUserInfo
-
} else {
-
console.log('获取用户登录态失败!' + res.errMsg)
-
}
-
//login
-
}
-
});
-
wx.checkSession({
-
success: function(){
-
//登录态未过期
-
},
-
fail: function(){
-
//登录态过期
-
wx.login()
-
}
-
});
-
},
-
globalData:{
-
userInfo:null,
-
ajaxUrl: "https://m.xxx.com/index.php",
-
baseUrl: "https://www.xxx.com/",