7
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 5 years have passed since last update.

slimでVue.jsのMustache構文 {{ }} を書く方法

Last updated at Posted at 2019-08-07

追記

とても勉強になるコメントを頂きました。ぜひコメント欄も含めてご覧ください。

対象のhtml.erb

sample.html.erb
<div id="app">
  <p>{{ name }}</p>
  <input v-model="name">
</div>
main.js
var app = new Vue({
  el: '#app',
  data: {
    name: 'hoge'
  }
})

素直にslimで {{}} を書くと……

sample.html.slim
#app
  p {{ name }}
  input v-model="name"

となると思いますが、これだとエラーがでます。
pタグにそのままMustache構文は書けないんですね。

追記

最初の { が p 要素の属性指定の始まりと解釈されるのに,その次にまた { が来て属性とは解釈しえない,ということですね。だからエラーになる。

↑コメントより引用

slimではこう書きます

sample.html.slim
#app
  p v-text="name"
  input v-model="name"

[別解]こんな書き方もあるらしい

sample.html.slim
#app
  p = "{{name}}"
  input v-model="name"

参考:https://qiita.com/moriyaman/items/14f7fda3a3b0895bc33f

7
7
2

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
7
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?