公司須要開發一個小程序,小程序也算是一個新興技術,就本身研究了一下,總結了一些開發過程須要注意的事項,供你們參考。html
「無 AppID」,沒法在真機上調試代碼,但不影響開發。html5
開發時是爲了方便調試,須要調用本地接口,能夠參考另外一篇博客;java
在小程序中使用<map>須要獲取位置經緯度,能夠在騰訊座標拾取器中獲取;web
1 var that = this; 2 var timer = setInterval(function(){ 3 progressNum++; 4 if(progressNum >= 100){ 5 clearInterval(timer) 6 }; 7 that.setData({ 8 progress:progressNum 9 }); 10 },30)
存儲輸入值
spring
1 wx.setStorageSync('storage', this.data.storage)
從存儲中獲得數據
json
1 var that; 2 Page( { 3 data: { 4 storage:'' 5 }, 6 onLoad: function(options) { 7 that = this; 8 //獲取存儲信息 9 wx.getStorage({ 10 key: 'storage', 11 success: function(res){ 12 // success 13 that.setData({ 14 storage:res.data 15 }) 16 } 17 }) 18 } 19 20 })
微信小程序端小程序
chooseImage(){ wx.chooseImage({ success: function (res) { var tempFilePaths = res.tempFilePaths wx.uploadFile({ url: 'http://127.0.0.1:8888/pesss/weChat/uploadImage.do', filePath: tempFilePaths[0], name: 'file', formData: { 'user': 'test' }, success: function (res) { var data = res.data //do something },fail:function(err){ console.log(err) } }) } }) }
java端微信小程序
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; @Controller public class ImageTestWebchatController { @RequestMapping(value = "/weChat/uploadImage", method = { RequestMethod.POST,RequestMethod.GET}) public ModelAndView uploadImage(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("進入get方法!"); MultipartHttpServletRequest req =(MultipartHttpServletRequest)request; MultipartFile multipartFile = req.getFile("file"); String realPath = "F:/image"; try { File dir = new File(realPath); if (!dir.exists()) { dir.mkdir(); } File file = new File(realPath,new Date().getTime() + ".jpg"); multipartFile.transferTo(file); } catch (IOException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } return null; } }