舒大少博客

一个95后少年的个人博客

当前时间为:
欢迎大家来到舒大少博客https://www.9713job.com,广告合作以及淘宝商家推广请微信联系15357240395

微信小程序之WXS脚本

2022-04-22 15:06:00
swq1822677238

手机扫码查看

微信小程序之WXS脚本
  1. 内嵌 WXS 脚本
    xxx.wxml

    <view>{{m1.toUpper(username)}}</view>
    <wxs module=”m1″>
      module.exports.toUpper=function(e){
        return e.toUpperCase()
      }
    </wxs>

    xxx.js

    data: {
        username:”username”
      },
  2. 定义外联 WXS 脚本
    在 tools文件夹下新建文件为 tools.wxs

    function toLower(str){
      return str.toLowerCase()
    }
    module.exports={
      toLower:toLower
    }
  3. 使用外联 WXS 脚本
    在WXML 中引入外联的wxs脚本时,必须为 wxs 标签添加 module 和 src 属性,其中:
    module 用来指定模块的名称
    src 用来指定要引入的脚本的绝对路径

发表评论

邮箱地址不会被公开。 必填项已用*标注