最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Passing props to element attributes in Vue components - Stack Overflow

programmeradmin3浏览0评论

When I try passing props to attributes of HTML elements in .vue files, they just stop rendering. What am I doing wrong?

script.js

import hInput from './components/hInput.vue'
Vueponent('h-input', hInput);
const app = new Vue({
    el: '#head',
});

index.php

<div id="head">
    <h1>{{config('app.name')}}</h1>
    <h-input placeholder="Hi" name="hello"></h-input>
</div>

hInput.vue

<template>
    <div>
        <input type="text" placeholder="{{placeholder}}">
    </div>
</template>

<script>
    export default {
        props: ['placeholder', 'name']
    };
</script>

When I try passing props to attributes of HTML elements in .vue files, they just stop rendering. What am I doing wrong?

script.js

import hInput from './components/hInput.vue'
Vue.component('h-input', hInput);
const app = new Vue({
    el: '#head',
});

index.php

<div id="head">
    <h1>{{config('app.name')}}</h1>
    <h-input placeholder="Hi" name="hello"></h-input>
</div>

hInput.vue

<template>
    <div>
        <input type="text" placeholder="{{placeholder}}">
    </div>
</template>

<script>
    export default {
        props: ['placeholder', 'name']
    };
</script>
Share Improve this question edited Oct 28, 2018 at 8:05 Mav asked Apr 4, 2017 at 14:35 MavMav 1,1901 gold badge17 silver badges38 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 19

Use the binding syntax, not text interpolation.

<template>
    <div>
        <input type="text" v-bind:placeholder="placeholder">
    </div>
</template>

There is also a shorthand.

<template>
    <div>
        <input type="text" :placeholder="placeholder">
    </div>
</template>
发布评论

评论列表(0)

  1. 暂无评论