This package is used to parse vue script section and it provides an interface to add, update and delete entities of different life cycles hooks of VueJS.
npm install vue-script-ast-parser
<script>
import parser from 'vue-script-ast-parser';
export default {
data() {
return {}
},
methods: {
parseCode() {
let code = `
import Vue from 'vue
import myComponent from 'myComponent'
export default {
data() {
return {
name: 'Kunal'
}
},
mounted() {
console.log('this is mounted')
}
methods: {
test(args1,args2) {
console.log('this is test method')
},
},
}`
let instance = new VueScriptParser(code)
console.log(instance)
}
}
}
</script>
{
"imports": [
"import Vue from 'vue",
"import myComponent from 'myComponent'"
],
"data": [
{
"key": "name",
"value": "Kunal"
}
],
"mounted": "\n console.log('this is mounted')\n ",
"methods": [
{
"name": "test",
"body": "\n console.log('this is test method')\n ",
"arguments": [
"args1",
"args2"
]
}
]
}
let instance = new VueScriptParser(code)
instance.addImport(importStatement)
let instance = new VueScriptParser(code)
instance.removeImport(importStatement)
let instance = new VueScriptParser(code)
instance.addData(variableName,value)
let instance = new VueScriptParser(code)
instance.removeData(variableName)
let instance = new VueScriptParser(code)
instance.addMounted(mountedBody)
let instance = new VueScriptParser(code)
instance.addMethod(name,body,args)
let instance = new VueScriptParser(code)
instance.removeMethod(methodName)