WeChat applet reads local data

In the utils folder, we can write the local data, encapsulate it into a .js file, provide an externally exposed interface, and then read the local data.

util.js:
function data(){
  let arr = [1,2,3]
  return arr
}

module.exports = {    
 date: date
}


Called in the page:
var fileData = require ('../../ utils / util.js')  
Page({   
  data: {    
    showData: fileData.data(),   
  },  
})


-------------------------------------------------- -----------------------------------------

170907 Modification:

Implemented directly with es6 syntax: (The thief is intuitive, okay)
util. js:
function data(){
  let arr = [1,2,3]
  return arr
}
export {data}


Called in the page:
import {data} from '../../utils/util'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326119829&siteId=291194637