[Vuejs]-Read all element bindings from a Vue template

0👍

I ended up solving this by getting the text of the render function (by calling vm.$options.render.toString() ) and then parsing the bindings from that.

For instance, the rendering function for a simple list view looks like this:

function() {
  var _vm = this
  var _h = _vm.$createElement
  var _c = _vm._self._c || _h
  return _c(
    "table",
    { attrs: { border: "1", cellpadding: "5", cellspacing: "0" } },
    [
      _vm._m(0),
      _vm._l(_vm.rows, function(row) {
        return _c("tr", [
          _c(
            "td",
            [
              _c("router-link", { attrs: { to: "/detail/" + row.ID } }, [
                _vm._v(_vm._s(_vm._f("truncate")(row.TITLE, 100)))
              ])
            ],
            1
          ),
          _c("td", [_vm._v(_vm._s(_vm._f("truncate")(row.DESCRIPTION, 200)))]),
          _c("td", [_vm._v(_vm._s(row.TYPE))])
        ])
      })
    ],
    2
  )
}

It looks like the bindings are always contained in an _s() element, and optionally a vm.f() instruction when using filters.

Leave a comment