微信小程序引入公用css及js

环境:

    微信小程序

首先看一下官方资料:

引入css:https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxss.html#%E6%A0%B7%E5%BC%8F%E5%AF%BC%E5%85%A5

引入js:

https://developers.weixin.qq.com/miniprogram/dev/reference/api/require.html

1. 引入公用样式实例:

页面结构wxml文件内容

这里实例是对class为demotext的文本进行样式更改

未处理样式时的显示效果如下:

样式文件内容:

新建公用样式文件:

引入公用wxss文件

样式效果:

2. 引入公用js实例:

新建公用js文件

    注:module.exports 发布需要被公用的函数

引入公用js,使用公用函数

效果:

3. 页面整体结构预览:

全部文件结构如下:

最后说明一下:以上代码只做方法演示使用,不规范之处还望海涵~

其他扩展:

        页面引入:https://developers.weixin.qq.com/miniprogram/dev/reference/wxml/import.html

发布了15 篇原创文章 · 获赞 14 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/master336/article/details/104331675