How the vue.compile string template parses the @ click method

let compileStr = Vue.compile(this.templateString)
this.template = compileStr.render
templateString: function (scope) {
      let fun = function () {
        console.log("afe")
      }
      return `
        <div>
          <el-button type="primary" @click="${fun}"></el-button>
          <el-button type="primary"></el-button>
        </div>
      `
    }

fun does not execute after clicking.

if changed to ${fun ()}, there is an error

Invalid handler for event "click": got undefined

is there any way to be able to compile and process, and click to execute fun? correctly What I am using now is to data the fun method

.
Apr.02,2021

`<el-button type="primary" @click="console.log('afe')"></el-button>`

the easiest way is to write the function body of fun directly into @ click.

@ click= "content" will be compiled like this:

</el-button>`

// 
{
  onclick: function () {
    (function fun() {
      console.log('afe')
    })()
  }
}
Menu