最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - (function () { [native code] }) on vue .js - Stack Overflow

programmeradmin2浏览0评论

I`m having an assignment where I have to make a simple quiz, each right question must add 1 points to the score, here is my code

let app = new Vue({
  el: '#app',
  data: {
    crameworks: [
    {skor: 0}
    ],
    frameworks: [
      { name: 'A.Charles Bababage', 
      votes : true },
      { name: 'B.Naruto',
       votes : false },
      { name: 'C.Sasuke',
       votes : false },
      { name: 'D.Belva',
       votes : false},
       ],
    grameworks : [
{ jawaban: 'A.Pochinok', 
      votes : true },
      { jawaban: 'B.Miramar',
       votes : false },
      { jawaban: 'C.Tambang',
       votes : false },
      { jawaban: 'D.Kampong',
       votes : false}
    ],
    vrameworks : [
      { answer: 'A.Bisa',
      votes : false},
      { answer: 'B.Tidak',
      votes : true},
      { answer: 'C.Mungkin',
      votes : false},
      { answer: 'D.isin ku aa crown',
      votes : false}
    ]
  },
  methods:{
  skor(){
    if(this.votes == true){
      this.crameworks[0].skor + 1
    }
  }
  }

})

here is my html file

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>My App</title>
    <script src="">
    </script>
</head>

<body>
    <div id="app">
        <ul>
        1.Pembuat Printer adalah
        <br>
        <p v-for="f in frameworks">
          <input type="radio">
                {{f.name}}
                        </p>
      </ul>
      <ul>
        2.Berikut area dalam game PUBG, Kecuali 
        <br>
            <p v-for="g in grameworks">
              <input type="radio">
            {{g.jawaban}} 
          </p>
      </ul>
      <ul>
        3.Bisakah Senjata Kar98K menggunakan Extended Sniper?
          <p v-for="v in vrameworks">
              <input type="radio">
              {{v.answer}}
          </p>
    <button type="submit" v-on:Click="skor">Jawab</button>
    <h1>Skor :  {{skor}}</h1>
    <script src="index.js"></script>
    </div>
  </body>
</html>

I give a true statement in every right answer so if user choose an answer with true statement it should be adding 1 points to the score and print the score, the problem is I get this warning (function () { [native code] }) when I'm trying to print the score, the score should be 0 at first

I`m having an assignment where I have to make a simple quiz, each right question must add 1 points to the score, here is my code

let app = new Vue({
  el: '#app',
  data: {
    crameworks: [
    {skor: 0}
    ],
    frameworks: [
      { name: 'A.Charles Bababage', 
      votes : true },
      { name: 'B.Naruto',
       votes : false },
      { name: 'C.Sasuke',
       votes : false },
      { name: 'D.Belva',
       votes : false},
       ],
    grameworks : [
{ jawaban: 'A.Pochinok', 
      votes : true },
      { jawaban: 'B.Miramar',
       votes : false },
      { jawaban: 'C.Tambang',
       votes : false },
      { jawaban: 'D.Kampong',
       votes : false}
    ],
    vrameworks : [
      { answer: 'A.Bisa',
      votes : false},
      { answer: 'B.Tidak',
      votes : true},
      { answer: 'C.Mungkin',
      votes : false},
      { answer: 'D.isin ku aa crown',
      votes : false}
    ]
  },
  methods:{
  skor(){
    if(this.votes == true){
      this.crameworks[0].skor + 1
    }
  }
  }

})

here is my html file

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>My App</title>
    <script src="https://cdn.jsdelivr/npm/vue">
    </script>
</head>

<body>
    <div id="app">
        <ul>
        1.Pembuat Printer adalah
        <br>
        <p v-for="f in frameworks">
          <input type="radio">
                {{f.name}}
                        </p>
      </ul>
      <ul>
        2.Berikut area dalam game PUBG, Kecuali 
        <br>
            <p v-for="g in grameworks">
              <input type="radio">
            {{g.jawaban}} 
          </p>
      </ul>
      <ul>
        3.Bisakah Senjata Kar98K menggunakan Extended Sniper?
          <p v-for="v in vrameworks">
              <input type="radio">
              {{v.answer}}
          </p>
    <button type="submit" v-on:Click="skor">Jawab</button>
    <h1>Skor :  {{skor}}</h1>
    <script src="index.js"></script>
    </div>
  </body>
</html>

I give a true statement in every right answer so if user choose an answer with true statement it should be adding 1 points to the score and print the score, the problem is I get this warning (function () { [native code] }) when I'm trying to print the score, the score should be 0 at first

Share Improve this question edited Jan 29, 2019 at 15:54 asked Jan 29, 2019 at 15:08 user8775227user8775227 2
  • 1 You've got a property called skor that's a function, and inside that function you try to add 1 to it. That does not make sense; you need a different property to keep the score value. – Pointy Commented Jan 29, 2019 at 15:09
  • im sorry this is my first assignment on vue, why it doesn't make sense? and what is different property that i needed ? – user8775227 Commented Jan 29, 2019 at 15:11
Add a ment  | 

3 Answers 3

Reset to default 2

The error is in skor, you forgot to add these parenthesis after it (), that's how you call a javascript function

<h1>Skor :  {{skor()}}</h1>

You're using the function skor to determine when to add +1, but your variable you're assigning to is wrong. It should be this.crameworks[0].skor + 1. Also, that should be the number 0 and not the string '0' in your data initialization.

You have also declared data twice in your Vue initializer. Combine those into a single data: {} object.

this.skor refers to the method, so the following is referencing the method:

<h1>Skor :  {{skor}}</h1>

In order to access the data you need to reference it in the right spot, crameworks[0].skor:

<h1>Skor :  {{crameworks[0].skor}}</h1>
发布评论

评论列表(0)

  1. 暂无评论