微信小程序學習筆記(三)

1、引入外部js方法

使用module.exports作爲出口對象,然後在需要用到數據的js文件中使用require函數接收該對象並獲取數據。

module.exports = {demo : data};

其中data是數據作爲一個屬性賦值給module.exports對象。

js文件中通過var data = require()引入。

注:引入js時微信小程序這裏只能使用相對路徑(../../),不能使用絕對路徑,否則會報錯。


2、微信小程序template模板

template屬於模板化複用,而不是組件化。

template引用到wxml方法是<import src="../../demo.js" />使用模板<template is="定義名" data="數據" />。

引用wxss方法是@import "demo/demo.wxss";即可將模板文件引入到wxss。


3、關於數據接收

微信小程序this.data現在已經失效。

新方法爲this.setData({})接收並更新到對應的變量中。


4、數據緩存

同步:

1.設置緩存:wx.setStorageSync(key,value);

2.獲取緩存:getStorageSync(key);

3.刪除緩存:removeStorageSync(key);

4.清除所有緩存:clearStorageSync();

異步:

1.設置緩存:wx.setStorage(key,value);

2.獲取緩存:getStorage(key);

3.刪除緩存:removeStorage(key);

4.清除所有緩存:clearStorage();

注意:緩存會永久存在,不能超過10mb。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章