Skip to content

Instantly share code, notes, and snippets.

@yourtion
Last active March 5, 2018 07:19
Show Gist options
  • Save yourtion/e36bccaadd8b5f45dd3a5482bd62638a to your computer and use it in GitHub Desktop.
Save yourtion/e36bccaadd8b5f45dd3a5482bd62638a to your computer and use it in GitHub Desktop.
JS技巧
function render(template, context) {
return template.replace(/\{\{(.*?)\}\}/g, (match, key) => context[key]);
}
const template = "{{name}}很厉name害,才{{age}}岁";
const context = { name: "yourtion", age: "15" };
console.log(render(template, context));
// 在main.js文件中添加一下代码
Vue.prototype.print = (obj,type) => {
type = type || "log";
const log = JSON.parse(JSON.stringify(obj));
console[type](log)
}
// 以后我们打印变量就可以直接使用
this.print(obj)
// 或者
this.print(obj,"error")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment