How to write JS code directly in WXML (WXS)

This article mainly introduces how to write JS code (wxs) directly in WXML, and the text is very detailed in the document, and there is a certain reference value for everyone’s learning or work. Friends need to refer to

In H6 development, we have to write to JS code in HTML, this is easy to implement. However, in WeChat applet, it is not possible to write JS code directly in WXML, so there is WXS. With WXS code in WXML, there are several ways (very clear in the small program document, I am just summarizing)

First type: directly in the WXML file

VAR NOW = getdate (); module.exports = {date: now}
 Current Time: {{DATEMODULE.DATE}      A second: similar to JS, write an external WXS file, and then references in WXML. For this, I will directly quote the example in the official document  
// Pages / datetool.wxsvar now = getdate (); var format = function ( Lastdate) {var Date = getdate (LastDate); returnate.tolocalestring ();} module.exports = {date: now, format: format}


  {DateTool.date}}  
[1
Third, another WXS file is referenced in a WXS file
      / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /,   

/ / /PAGES / REQUIRE (“./ Tools.wxs “); console.log (Tools.foo); console.log (” logic.wxs “)); console.log (Tools.msg);

   
WXS syntax and JS are very similar, but must pay attention to the WXS file outside After you want to give it an Exports property setting value
  module.exports = {key1: value1, key2: value2,};  
The above is all of this article, I hope to help everyone, I hope everyone will support Tumi Clouds.
                    
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment