第二十六天:关于小程序的公共文件的引用
<h4>小程序知识点</h4>
<h5>- 1.引入公共js</h5>
<pre><code class="language-javacript">封装 : function a(b){
` }
暴露函数:module.exports = {
a : a
}
var common = require('../../utils/common.js') ;
使用:common.a</code></pre>
<h5>- 2.引入公共css</h5>
<pre><code class="language-javascript">引入 : @import "common.wxss";</code></pre>
<h5>- 3.引入公共wxml</h5>
<h5>- 3-1 template引入</h5>
<pre><code class="language-javascript">// 公共模板 template name
<!-- item.wxml -->
<template name="home_item" >
<text>{{text}}</text>
</template>
//引入公共模板
<import src="item.wxml"/>
<template is="home_item" data = "{{text : 'haha'}}"/> //在这里引用模板</code></pre>
<h5>- 3-2 include(除了template的代码可以全部引入)</h5>
<p>include可以将目标文件<strong>除了<template/></strong>的整个代码引入,相当于是拷贝到include位置,如:</p>
<pre><code class="language-javascript"><!-- index.wxml -->
<include src="header.wxml"/>
<view> body </view>
<include src="footer.wxml"/>
<!-- header.wxml -->
<view> header </view>
<!-- footer.wxml -->
<view> footer </view>
</code></pre>