Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

vue.js - Vue - set default value to input text

I'm loading a Vue component which should render a basic form. I'm trying to set the input to have a default value, but for some reason nothing shows. Here is what i tried:

<template>
    ...
    <input type="text" value="0.02" class="form-control" v-model="amount">
    ...
</template>

Why does nothing show into the input field? Is it because Vue doesn't support it or i need to use something else? Thanks in advance


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The default value is set in data as follows:

new Vue({
  el:"#app",
  data() { return { amount: "0.02" } }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
  <input type="text" class="form-control" v-model="amount">
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...