Skip to content

Commit

Permalink
opti template
Browse files Browse the repository at this point in the history
  • Loading branch information
errorrik committed Oct 16, 2021
1 parent 6f21586 commit 6465416
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,18 @@ export function defineComponent(creator, san) {
*
* @param {string} tpl 组件的模板,支持tagged template string
*/
export function template(tpl, ...vars) {
export function template(tpl) {
if (context.creator) {
// 支持tagged template string
context.template = Array.isArray(tpl)
? tpl.slice(1).reduce((acc, cur, index) => acc + vars[index] + cur, tpl[0])
: tpl;
if (tpl instanceof Array) {
let realTpl = tpl[0];
for (let i = 1, l = tpl.length; i < l; i++) {
realTpl += arguments[i] + tpl[i];
}
context.template = realTpl;
}
else {
context.template = tpl;
}
}
};

Expand Down

0 comments on commit 6465416

Please sign in to comment.