要求,用户通过界面输入一个函数,比如,用户对点击事件进行处理,调用一个函数,函数内容就是 console.log(123),我需要把这些生成源码,生成后的源码就是这样的methods: { handleSubmit() { console.log(123) } }最好是带有格式的,就是排好版的
格式化的话可以使用 Prettier。import prettier from "https://unpkg.com/prettier@2.7.1/esm/standalone.mjs"; import parserGraphql from "https://unpkg.com/prettier@2.7.1/esm/parser-graphql.mjs"; prettier.format("type Query { hello: String }", { parser: "graphql", plugins: [parserGraphql], });
提示:用
new Function(....)
遇到具体的困难来再详述你的问题。