mixin
后台内置 3 个 mixin
,分别是 Mixins.table
Mixins.form
Mixins.select
。
通常可以混入不同的 mixin
简化我们的代码。比如 index
页面是列表,add
页面是新增,edit
页面是编辑,select
页面是选择
define([], function() {
return {
index: { // 对应index方法
Yi.vue.mixin(Mixins.table);
return {
template: '#app',
data: function() {
return {}
},
methods: {
...
}
};
},
add: { //对应add方法
Yi.vue.mixin(Mixins.form);
...
},
edit: { // 对应edit 方法
Yi.vue.mixin(Mixins.form);
...
},
select: { // 对应select方法
Yi.vue.mixin(Mixins.table);
Yi.vue.mixin(Mixins.select);
...
}
};
});
<p>后台内置 3 个 <code>mixin</code>,分别是 <code>Mixins.table</code> <code>Mixins.form</code> <code>Mixins.select</code>。<br>通常可以混入不同的 <code>mixin</code> 简化我们的代码。比如 <code>index</code> 页面是列表,<code>add</code> 页面是新增,<code>edit</code> 页面是编辑,<code>select</code> 页面是选择</p>
<pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code><span class="pln">define</span><span class="pun">([],</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L1"><code><span class="pln"> </span><span class="kwd">return</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L2"><code><span class="pln"> index</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// 对应index方法</span></code></li><li class="L3"><code><span class="pln"> </span><span class="typ">Yi</span><span class="pun">.</span><span class="pln">vue</span><span class="pun">.</span><span class="pln">mixin</span><span class="pun">(</span><span class="typ">Mixins</span><span class="pun">.</span><span class="pln">table</span><span class="pun">);</span></code></li><li class="L4"><code><span class="pln"> </span><span class="kwd">return</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L5"><code><span class="pln"> </span><span class="kwd">template</span><span class="pun">:</span><span class="pln"> </span><span class="str">'#app'</span><span class="pun">,</span></code></li><li class="L6"><code><span class="pln"> data</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L7"><code><span class="pln"> </span><span class="kwd">return</span><span class="pln"> </span><span class="pun">{}</span></code></li><li class="L8"><code><span class="pln"> </span><span class="pun">},</span></code></li><li class="L9"><code><span class="pln"> methods</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L0"><code><span class="pln"> </span><span class="pun">...</span></code></li><li class="L1"><code><span class="pln"> </span><span class="pun">}</span></code></li><li class="L2"><code><span class="pln"> </span><span class="pun">};</span></code></li><li class="L3"><code><span class="pln"> </span><span class="pun">},</span></code></li><li class="L4"><code><span class="pln"> add</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">//对应add方法</span></code></li><li class="L5"><code><span class="pln"> </span><span class="typ">Yi</span><span class="pun">.</span><span class="pln">vue</span><span class="pun">.</span><span class="pln">mixin</span><span class="pun">(</span><span class="typ">Mixins</span><span class="pun">.</span><span class="pln">form</span><span class="pun">);</span></code></li><li class="L6"><code><span class="pln"> </span><span class="pun">...</span></code></li><li class="L7"><code><span class="pln"> </span><span class="pun">},</span></code></li><li class="L8"><code><span class="pln"> edit</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// 对应edit 方法</span></code></li><li class="L9"><code><span class="pln"> </span><span class="typ">Yi</span><span class="pun">.</span><span class="pln">vue</span><span class="pun">.</span><span class="pln">mixin</span><span class="pun">(</span><span class="typ">Mixins</span><span class="pun">.</span><span class="pln">form</span><span class="pun">);</span></code></li><li class="L0"><code><span class="pln"> </span><span class="pun">...</span></code></li><li class="L1"><code><span class="pln"> </span><span class="pun">},</span></code></li><li class="L2"><code><span class="pln"> </span><span class="kwd">select</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// 对应select方法</span></code></li><li class="L3"><code><span class="pln"> </span><span class="typ">Yi</span><span class="pun">.</span><span class="pln">vue</span><span class="pun">.</span><span class="pln">mixin</span><span class="pun">(</span><span class="typ">Mixins</span><span class="pun">.</span><span class="pln">table</span><span class="pun">);</span></code></li><li class="L4"><code><span class="pln"> </span><span class="typ">Yi</span><span class="pun">.</span><span class="pln">vue</span><span class="pun">.</span><span class="pln">mixin</span><span class="pun">(</span><span class="typ">Mixins</span><span class="pun">.</span><span class="kwd">select</span><span class="pun">);</span></code></li><li class="L5"><code><span class="pln"> </span><span class="pun">...</span></code></li><li class="L6"><code><span class="pln"> </span><span class="pun">}</span></code></li><li class="L7"><code><span class="pln"> </span><span class="pun">};</span></code></li><li class="L8"><code><span class="pun">});</span></code></li></ol></pre>