1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Vue.js 3.0(beta 20) helloworld

Last updated at Posted at 2020-07-12

Vue.js 2.x で書いた hello world を Vue.js 3.0 beta を使って書き換え

CDNを使ってHTMLファイルとして作っています。
Composition APIは使ってません。

Vue.js 2.x

<!DOCTYPE html>
<html lang="ja">
<meta charset="utf-8">
<title>hello world</title>
<div id="app">
  <p>{{ display }}</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.6/dist/vue.js"></script>
<script>
  new Vue({
    el: '#app',
    data: { display: 'Hello World!' }
  });
</script>

Vue.js 3.0.0-beta.20

<!DOCTYPE html>
<html lang="ja">
<meta charset="utf-8">
<title>hello world</title>
<div id="app">
  <p>{{ display }}</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@3.0.0-beta.20/dist/vue.global.js"></script>
<script>
  const app = Vue.createApp({
    data: () => ({
      display: 'Hello World!'
    })
  });
  app.mount('#app');
</script>

ポイント

  • Vueコンストラクタの代わりに、createAppを使います。
  • data オプションはコンポーネントと同様に、関数にする必要があります。
  • elオプションの代わりに、mountを使います。
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?