首页 > 技术文章 > 用Vue写选项卡组件

yangcaicai 2020-12-21 22:32 原文

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
      .a {
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <span class="a" v-for="(n ,i)  in arr " @click="f1(i)">{{n}}</span>
      <div>{{content}}</div>
    </div>
    <script>
      let vm = new Vue({
        el: "#app",
        data: {
          arr: ["选项卡1", "选项卡2", "选项卡3"],
          arr1: ["内容1", "内容2", "内容3"],
          content: "内容1",
        },
        methods: {
          f1(i) {
            this.content = this.arr1[i];
          },
        },
      });
    </script>
  </body>
</html>
效果如下:

 

 

推荐阅读