tangbc / sugar

A lightweight and powerful JavaScript MVVM library. Used for production or learning how to make a full MVVM.
https://github.com/tangbc/sugar/wiki
MIT License
352 stars 60 forks source link

请教一下 怎么在 内联函数里面 调用 alert 方法? #6

Open sgf opened 5 years ago

sgf commented 5 years ago

提示报错。

@tangbc 内联代码: <td v-on:click=" if (ok) { alert('11'); } else { alert('22'); }">啊啊啊</td>

Uncaught TypeError: scope.alert is not a function
    at Object.eval (eval at createAnonymous (mvvm.js:1313), <anonymous>:3:52)
    at HTMLTableCellElement.listenerAgent (mvvm.js:1409)

另外我觉得题主这个项目非常厉害。 为什么,因为,其实我是用它来代替 knockout 来用的。我觉得替代或者超越vue几乎很难,但是如果替代或者超越ko却很容易。

另外有没有QQ群 用来交流。。

tangbc commented 5 years ago

这其实是我自己学习 Vue 源码之后自己倒腾的小项目,其实也有一些 bug 的 😂

提示 scope.alert is not a function 是因为在语句解析的时候没有把 window 下的全局方法和常量单独匹配,全当做 data 对象里面的作用域处理了,之后我可以处理下,现在可以先:

model: {
    alert: function (str) {
        alert(str)
    }
}

来代替。

sgf commented 5 years ago

谢谢。