1. 程式人生 > >vue中method呼叫另一個method獲取不到引數的問題

vue中method呼叫另一個method獲取不到引數的問題

this.$options.methods.fun2();

fun2()獲取不到引數,為underfind,改為如下即可。 

this.fun2()

以下為完整程式碼: 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/
[email protected]
/dist/vue.js"></script> <title>RunJS 演示程式碼</title> </head> <body> <div id="helloApp"> {{test}} <button @click="fun1"> te</button> </div> </body> <script> var helloApp = new Vue({ el: "#helloApp", data: { test: "200" }, methods: { fun1() { this.test = "300" this.fun2() }, fun2() { alert(this.test) this.test = "400" } } }) </script>