| 除了直接绑定到一个方法,也可以在内联 JavaScript 语句中调用方法: 
 <div id="inline-handler">
 <button @click="say('hi')">Say hi</button>
 <button @click="say('what')">Say what</button>
 </div>
 Vue.createApp({
 methods: {
 say(message) {
 alert(message)
 }
 }
 }).mount('#inline-handler')
 结果: 点击此处实现
 
 有时也需要在内联语句处理器中访问原始的 DOM 事件。可以用特殊变量 $event 把它传入方法:
 
 <button @click="warn('Form cannot be submitted yet.', $event)">
 Submit
 </button>
 // ...
 methods: {
 warn(message, event) {
 // now we have access to the native event
 if (event) {
 event.preventDefault()
 }
 alert(message)
 }
 }
 |