Last active
March 5, 2018 07:19
-
-
Save yourtion/e36bccaadd8b5f45dd3a5482bd62638a to your computer and use it in GitHub Desktop.
JS技巧
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 在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