[Vuejs]-How can I get HTML element when importing Vue via CDN?

3👍

Try something like this

  <script src="https://unpkg.com/vue@3.0.2"></script>
  </head>
  <body>
    <div id="app">
      <h1>{{ data }}</h1>
      <input type="text" ref="input">
      <button @click="log">LOG</button>
    </div>
    <script>
      const app = Vue.createApp({
        data() {
          return {
            data: 'any'
          }
        },
        methods: {
          log() {
            console.log(this.$refs.input.value)
          }
        }
      });

      app.mount('#app')
    </script>

Leave a comment