扫码关注官方订阅号
人生最曼妙的风景,竟是内心的淡定与从容!
让你html里绑定一个动态的文字就好了:
html
<p class='container' id="app"> <p class="dropdown"> <input type="hidden" name="amount" v-model="chosenAmount" value=""> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" > {{ chosenAmount }} </button> <p class="dropdown-menu" aria-labelledby="dropdownMenu1"> <a class="dropdown-item" v-for="item in items" v-on:click="fillIn(item)" data-salary="{{item.message}}">{{ item.message }}个</a> </p> </p> </p>
var amount = new Vue({ el: '#app', data:{ chosenAmount: '', items: [ {message: '1'}, {message: '2'}, {message: '3'} ] }, ready: function(){ //这个初始化不能放在data里仅仅是因为bootstrap.js也会对data-toggle="dropdown"进行一些transform,那会覆盖掉初始化在data中的值。于是我们选择了生命周期的ready里,即在bootstrap处理之后再绑定初始文字 this.chosenAmount = '请选择数量'; }, methods: { fillIn: function (item) { this.chosenAmount = item.message; } } });
https://jsfiddle.net/hsfzxjy/esw77kjt/3/
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
让你
html里绑定一个动态的文字就好了:https://jsfiddle.net/hsfzxjy/esw77kjt/3/