13
7

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❏

Last updated at Posted at 2019-12-13

開発環境はJSFiddleで!
https://qiita.com/ITmanbow/items/9ae48d37aa5b847f1b3b

#① data内のプロパティを直接書き込んで表示させることができる

html
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<div id="app">
  <p>{{ message }}</p>
</div>
javascript
new Vue({
  el: "#app",
  data: {
    message: "hello world!"
  }
})

【出力結果】
hello world!


#② javascript式を書くことができる
html
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<div id="app">
  <p>{{ message }}</p>
  <p>{{ number + 5 }}</p>
</div>
javascript
new Vue({
  el: "#app",
  data: {
    message: "hello world!"
    number: 3
  }
})

【出力結果】
hello world!
8


#③ 三項演算子を書くことができる
html
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<div id="app">
  <p>{{ message }}</p>
  <p>{{ number + 5 }}</p>
  <p>{{ ok ? "YES" : "NO" }}</p>
</div>
javascript
new Vue({
  el: "#app",
  data: {
    message: "hello world!"
    number: 3
    ok: true
  }
})

【出力結果】
hello world!
8
YES


#④ メソッドを書くことができる
html
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<div id="app">
  <p>{{ message }}</p>
  <p>{{ number + 5 }}</p>
  <p>{{ ok ? "YES" : "NO" }}</p>
  <p>{{ sayHi() }}</p>
</div>
javascript
new Vue({
  el: "#app",
  data: {
    message: "hello world!"
    number: 3
    ok: true
  },
  methods: {
    sayHi: function() {
      return "Hi";
    }
  }
})

【出力結果】
hello world!
8
YES
Hi


ではまた!
13
7
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
13
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?