


About running WeChat applet on Chrome browser and using WebStorm
This article mainly introduces the relevant information about running WeChat applet on Chrome browser and the use of WebStorm. Friends in need can refer to the development framework of
"WeChat applet" to experience it. Not bad - it comes with a UI framework. But the problem is that his IDE performs quite poorly - in fact, it is mainly because I bought the WebStorm License for many years. Therefore, I think his IDE is really not as useful as my paid one.
Moreover, as a "Chief Markdown Programmer of GitHub China" who supports freedom and open source. WeChat’s “WeChat Mini Program” is leading the Web to open and close, and we can no longer happily share our code.
If we let it go, the future Web world will be worrying.
Okay, enough nonsense:
The article is too long and you don’t want to read it, you can just watch the Demo haha:
GitHub: https://github.com/phodal/weapp -webdemo
Preview: http://weapp.phodal.com/
The three basic elements of MINA in the real world
Behind the "WeChat Mini Program" It is running a framework called MINA. In the previous articles, we have almost introduced it. Now let us introduce the pipeline:
Transform wxml and wxss
When we modify WXML and WXSS, we need to recompile the project to see the effect on the browser. At this time, the background will perform some transform actions:
1.wcc will convert wxml into a genrateFun. Executing this method will get a virtual dom
2.wxss will convert wxss into css - this One point is debatable.
wcc and wxss can be obtained from the vendor directory. Type help under "WeChat Web Developer Tools" and you will get the following:
Run openVendor(), and you will get the four files above wcss, wxss, WAService.js, and WAWebview.js.
Transform js file
For js files, it is an assembly process. The following is our app.js file:
App({ onLaunch: function () { } })
After conversion it will become:
define("app.js", function(require, module){var window={Math:Math}/*兼容babel*/,location,document,navigator,self,localStorage,history,Caches; App({ onLaunch: function () { } }) }); require("app.js");
I pretend you already know what this is, anyway I don’t want to, nor can I explain it~~. Same as:
define("pages/index/index.js", function(require, module){var window={Math:Math}/*兼容babel*/,location,document,navigator,self,localStorage,history,Caches; Page({ data: { text: initData } }); require("pages/index/index.js");
As for how it is replaced or appended to html, I will not explain it.
How does MINA run?
In order to run a Page, we need to have a virtual dom, that is, a function converted with wcc, such as:
/*v0.7cc_20160919*/ var $gwxc var $gaic={} $gwx=function(path,global){ function _(a,b){b&&a.children.push(b);} function _n(tag){$gwxc++;if($gwxc>=16000){throw 'enough, dom limit exceeded, you don\'t do stupid things, do you?'};return {tag:tag.substr(0,3)=='wx-'?tag:'wx-'+tag,attr:{},children:[]}} function _s(scope,env,key){return typeof(scope[key])!='undefined'?scope[key]:env[key]} function _wl(tname){console.warn('template `' + tname + '` is being call recursively, will be stop.')} function _ai(i,p,e,me){var x=_grp(p,e,me);if(x)i.push(x);else{console.warn('path `'+p+'` not found from `'+me+'`')}} function _grp(p,e,me){if(p[0]!='/'){var mepart=me.split('/');mepart.pop();var ppart=p.split('/');for(var i=0;i<ppart.length;i++){if( ppart[i]=='..')mepart.pop();else if(!ppart[i])continue;else mepart.push(ppart[i]);}p=mepart.join('/');}if(me[0]=='.'&&p[0]=='/')p='.'+p;if(e[p])return p;if(e[p+'.wxml'])return p+'.wxml';} //以下省略好多字。
Then in our Adding a script to the html, such as
document.dispatchEvent(new CustomEvent("generateFuncReady", { detail: { generateFunc: $gwx('index.wxml') } }))
will trigger this event. I simply split WXWebview.js and got several functional components:
define.js, this is where AMD modularization is defined
exparser.js, used to convert WXML tags to HTML tags
- ##exparser-behvaior.js, defines some behaviors of different tags
- mobile.js, is supposed to be an event library, I don't seem to care.
- page.js, the core code, where Page and App are defined.
- report.js, everything you say can be used as your evidence in court.
- virtual_dom.js, a virtual dom implementation combined with wcc, there should be component.css in it, or it may be called weui
- wa -wx.js, where various WeChat APIs, WebView and Native are defined, conflicts with the WX below.
- wx.js, same as above, but slightly different.
- wxJSBridge.js, Weixin JS Bridge
document.addEventListener("generateFuncReady", function (e) { var generateFunc = e.detail.generateFunc; wx.onAppDataChange && generateFunc && wx.onAppDataChange(function (e) { var i = generateFunc((0, d.getData)()); if (i.tag = "body", e.options && e.options.firstRender){ e.ext && ("undefined" != typeof e.ext.webviewId && (window.__webviewId__ = e.ext.webviewId), "undefined" != typeof e.ext.downloadDomain && (window.__downloadDomain__ = e.ext.downloadDomain)), v = f(i, !0), b = v.render(), b.replaceDocumentElement(document.body), setTimeout(function () { wx.publishPageEvent(p, {}), r("firstRenderTime", n, Date.now()), wx.initReady && wx.initReady() }, 0); } else { var o = f(i, !1), a = v.diff(o); a.apply(b), v = o, document.dispatchEvent(new CustomEvent("pageReRender", {})); } }) })
<wx-view class="btn-area"> <wx-view class="body-view"> <wx-text><span style="display:none;"></span><span></span></wx-text> <wx-button>add line</wx-button> <wx-button>remove line</wx-button> </wx-view> </wx-view>
<view class="btn-area"> <view class="body-view"> <text>{{text}}</text> <button bindtap="add">add line</button> <button bindtap="remove">remove line</button> </view> </view>
Developed using WebStorm
Before running on the browser, we need to simply mock some methods, such as:- window.webkit.messageHandlers.invokeHandler.postMessage ##window.webkit.messageHandlers.publishHandler.postMessage
- WeixinJSCore.publishHandler
- WeixinJSCore..invokeHandler
- Then change some contents in config.json into __wxConfig, such as:
__wxConfig = { "debug": true, "pages": ["index"], "window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "WeChat", "navigationBarTextStyle": "black" }, "projectConfig": { }, "appserviceConfig": { }, "appname": "fdfafafafafafafa", "appid": "touristappid", "apphash": 2107567080, "isTourist": true, "userInfo": {} }
For example, our app name here is Hahahahahahahahahahahahahahahahahahahahaha-my home is in Fujian.
Then introduce each js file into our html, la la.
我们还需要一个自动化的glup脚本来watch wxml和wxss的修改,然后编译,如:
exec('./vendor/wcc -d ' + inputPath + ' > ' + outputFileName, function(err, stdout, stderr) { console.log(stdout); console.log(stderr); });
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
微信小程序页面跳转功能中从列表的item项跳转到下一个页面的实现方法
The above is the detailed content of About running WeChat applet on Chrome browser and using WebStorm. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Every application you run on Windows has a component program to update it. So if you are using Google Chrome or Google Earth, it will run a GoogleUpdate.exe application, check if an update is available, and then update it based on the settings. However, if you no longer see it and instead see a process updater.exe in the Task Manager of Windows 11/10, there is a reason for this. What is Updater.exe in Windows 11/10? Google has rolled out updates for all its apps like Google Earth, Google Drive, Chrome, etc. This update brings

Xianyu's official WeChat mini program has quietly been launched. In the mini program, you can post private messages to communicate with buyers/sellers, view personal information and orders, search for items, etc. If you are curious about what the Xianyu WeChat mini program is called, take a look now. What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3. If you want to use it, you must activate WeChat payment before you can purchase it;

Chrome's inability to load plug-ins can be solved by checking whether the plug-in is installed correctly, disabling and enabling the plug-in, clearing the plug-in cache, updating the browser and plug-ins, checking the network connection, and trying to load the plug-in in incognito mode. The solution is as follows: 1. Check whether the plug-in has been installed correctly and reinstall it; 2. Disable and enable the plug-in, click the Disable button, and then click the Enable button again; 3. Clear the plug-in cache, select Advanced Options > Clear Browsing Data, check cache images and files and clear all cookies, click Clear Data.

What is the Chrome plug-in extension installation directory? Under normal circumstances, the default installation directory of Chrome plug-in extensions is as follows: 1. The default installation directory location of chrome plug-ins in windowsxp: C:\DocumentsandSettings\username\LocalSettings\ApplicationData\Google\Chrome\UserData\Default\Extensions2. chrome in windows7 The default installation directory location of the plug-in: C:\Users\username\AppData\Local\Google\Chrome\User

What should I do if the Google Chrome web page cannot be opened? Many friends like to use Google Chrome. Of course, some friends find that they cannot open web pages normally or the web pages open very slowly during use. So what should you do if you encounter this situation? Let’s take a look at the solution to the problem that Google Chrome web pages cannot be opened with the editor. Solution to the problem that the Google Chrome webpage cannot be opened. Method 1. In order to help players who have not passed the level yet, let us learn about the specific methods of solving the puzzle. First, right-click the network icon in the lower right corner and select "Network and Internet Settings." 2. Click "Ethernet" and then click "Change Adapter Options". 3. Click the "Properties" button. 4. Double-click to open i

This tutorial shows you how to find specific text or phrases on all open tabs in Chrome or Edge on Windows. Is there a way to do a text search on all open tabs in Chrome? Yes, you can use a free external web extension in Chrome to perform text searches on all open tabs without having to switch tabs manually. Some extensions like TabSearch and Ctrl-FPlus can help you achieve this easily. How to search text across all tabs in Google Chrome? Ctrl-FPlus is a free extension that makes it easy for users to search for a specific word, phrase or text across all tabs of their browser window. This expansion

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: <!--index.wxml-->&l

WeChat applet implements picture upload function With the development of mobile Internet, WeChat applet has become an indispensable part of people's lives. WeChat mini programs not only provide a wealth of application scenarios, but also support developer-defined functions, including image upload functions. This article will introduce how to implement the image upload function in the WeChat applet and provide specific code examples. 1. Preparatory work Before starting to write code, we need to download and install the WeChat developer tools and register as a WeChat developer. At the same time, you also need to understand WeChat
