码迷,mamicode.com
首页 > 其他好文 > 详细

let var作用域

时间:2021-07-01 17:16:20      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:oct   ons   cli   tns   body   elements   作用   hello   vue   

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <p>{{ message }}</p>

      <button type="button" v-on:click="getNum()">1</button>
      <button type="button" v-on:click="getNum()">2</button>
      <button type="button" v-on:click="getNum()">3</button>
    </div>

    <script>
      const app = new Vue({
        el: ‘#app‘,
        data: {
          message: ‘Hello Vue.js!‘,
          firstName: "thomas",
          lastName: "zhang",
        },
        methods: {
          getNum: function() {
            const btns = document.getElementsByTagName(‘button‘);
            for (var i = 0; i < btns.length; i++) {
              btns[i].addEventListener(‘click‘, function() {
                console.log(‘button ‘ + i + ‘ click‘);
              })
            }

            for (let i = 0; i < btns.length; i++) {
              btns[i].addEventListener(‘click‘, function() {
                console.log(‘button ‘ + i + ‘ click‘);
              })
            }
          }
        },
        computed: {}
      })
    </script>
  </body>
</html>

技术图片

let var作用域

标签:oct   ons   cli   tns   body   elements   作用   hello   vue   

原文地址:https://www.cnblogs.com/zhangxuechao/p/14958283.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!