[Vue] 여러개의 Vue 인스턴스 사용하기

bery·2020년 9월 16일
0
post-custom-banner
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>뷰 기초 익히기</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  </head>
  <body>
    <div id="app">
      {{ name }} <br />
      <button @click="changeText">Click</button>
    </div>
    <div id="app-1">
      {{ name }}<br />
      <button @click="changeText">Click</button>
    </div>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          name: "eunbyul",
        },
        methods: {
          changeText() {
            app1.name = "eunbyul updated";
          },
        },
      });

      const app1 = new Vue({
        el: "#app-1",
        data: {
          name: "eunbyul1",
        },
        methods: {
          changeText() {
            app.name = "eunbyul1 updated";
          },
        },
      });
    </script>
  </body>
</html>
post-custom-banner

0개의 댓글