0

why cant show {{myGame}},the result should be 超級馬力歐 at first, and will change it when user press the button, but it didn't and it just show {{myGame}} . i dont know how to fix it , thank you !!!

let myApp = new vue({
  
  el:'myApp',
  data:{
     myGame:'超級馬力歐'
  },
  
  methods:{
    
    btnClick: function(pname){
      this.myGame = pname;
    },
  },
  
});
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  
  <title>JS Bin</title>
</head>
<body>
  
  <div id="myApp" >
    <p> 您最喜歡的遊戲是:{{myGame}}</p>
    
    <button v-on:click="btnClick('我的世界')">我的世界</button>
    <button v-on:click="btnClick('我的世界33')">我的世界33</button>
    <button v-on:click="btnClick('我的世界44')">我的世界44</button>
    <button @click="btnClick('我的世11界')">我的世11界</button>
   
   <script src="https://unpkg.com/[email protected]/dist/vue.js"></script> 
  </div>

</body>
</html>

2
  • 2
    Have a look at the browser console, your mistakes will show up there. Commented Jun 1, 2018 at 18:17
  • You reference vue not the way you should, and secondly you reference the app element in a wrong way. Good comment above - always look at your console Commented Jun 1, 2018 at 18:26

1 Answer 1

2

This is the fixed script for you. As a general advice, in future try to read your console and thus figure out the origin of mistake. The problems were that you reference vue not the way you should, and secondly you reference the app element in a wrong way

let myApp = new Vue({
  
  el:'#myApp',
  data:{
     myGame:'超級馬力歐'
  },
  
  methods:{
    
    btnClick: function(pname){
      this.myGame = pname;
    },
  },
  
});
  
  <div id="myApp" >
    <p> 您最喜歡的遊戲是:{{myGame}}</p>
    
    <button v-on:click="btnClick('我的世界')">我的世界</button>
    <button v-on:click="btnClick('我的世界33')">我的世界33</button>
    <button v-on:click="btnClick('我的世界44')">我的世界44</button>
    <button @click="btnClick('我的世11界')">我的世11界</button>
    
  </div>

<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.