zoukankan      html  css  js  c++  java
  • Vue.js之下拉列表及选中触发事件

      1、下拉列表

      (1)、html部分代码:

    <div id="app">
      <select v-model="selected">   <option>--请选择--</option>   <option v-for="item in optList">{{ item }}</option>   </select>
    </div>

      

      (2)、js部分代码:

    new Vue({
       el: '#app',
       data: {
         selected: '',     
         optList: ['青龙', '白虎', '朱雀', '玄武']                                
       }   
    })
    

      

      结果就是这样:

           

      (2)、选中选项触发事件

      这种情况下,可以使用change事件,当选中某一选项后,便会触发该事件。完整代码:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>Document</title>
    	<script src="https://cdn.bootcss.com/vue/2.5.13/vue.min.js"></script>
    </head>
    <body>
    	<div id="app">
    		<select name="" id="" v-model="select2" @change='getValue'>
    			<option value="">--请选择--</option>
    			<option v-for='item in optionList'>{{ item }}</option>
    		</select>
    	</div>
    	<script>
    		new Vue({
    			el: '#app',
    			data: {
    				select2: '',
    				optionList: ['青龙', '白虎', '朱雀', '玄武']
    			},
    			methods: {
    				getValue: function(){
    					console.log('您选择了', this.select2)
    				}
    			}
    		})
    	</script>
    </body>
    </html>
    
  • 相关阅读:
    逐步实现python版wc命令
    Linux中短横线(-)小记
    memcached启动脚本(class练习)
    nginx启动脚本(class练习)
    Python-类的方法
    re模块
    shutil模块
    时间模块(time/date)
    迭代器
    生成器
  • 原文地址:https://www.cnblogs.com/sunjuncoder/p/9895021.html
Copyright © 2011-2022 走看看