When I try passing props to attributes of HTML elements in .vue
files, they just stop rendering. What am I doing wrong?
script.js
JavaScript
x
6
1
import hInput from './components/hInput.vue'
2
Vue.component('h-input', hInput);
3
const app = new Vue({
4
el: '#head',
5
});
6
index.php
JavaScript
1
5
1
<div id="head">
2
<h1>{{config('app.name')}}</h1>
3
<h-input placeholder="Hi" name="hello"></h-input>
4
</div>
5
hInput.vue
JavaScript
1
12
12
1
<template>
2
<div>
3
<input type="text" placeholder="{{placeholder}}">
4
</div>
5
</template>
6
7
<script>
8
export default {
9
props: ['placeholder', 'name']
10
};
11
</script>
12
Advertisement
Answer
Use the binding syntax, not text interpolation.
JavaScript
1
6
1
<template>
2
<div>
3
<input type="text" v-bind:placeholder="placeholder">
4
</div>
5
</template>
6
There is also a shorthand.
JavaScript
1
6
1
<template>
2
<div>
3
<input type="text" :placeholder="placeholder">
4
</div>
5
</template>
6