如何利用Vue实现长尾词的智能搜索功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计535个文字,预计阅读时间需要3分钟。
概述+学习Vue的第二节,由于2.0版本不再向下兼容,视频中的不少内容不能实现。以下列出一些主要知识点:/\/v-on可简写为@/事件冒泡是指点击div内部的button时触发show1()函数,自然会冒泡到点击div内部。
简述
学习vue的第二节,由于2.0版本并不向下兼容,视频中的不少内不能实现。下面列出一些主要知识点
// v-on 可简写为@ // 事件冒泡是指当点击div内部的button触发show1()时,必然会冒泡到div上执行show2(),这才层级div中很常见 // 阻止冒泡,原生js法,设置事件对象的cancelBubble属性为true // vue方法@click.stop // 阻止默认行为,原生js法,设置事件对象的preventDefault属性为true // vue方法@contextmenu.prevent // 键盘事件获取键码,原生js法,使用事件对象的keyCode属性 // vue方法@keyup.键码或键名,如获取按下回车@keydown.13 或 @keydown.enter // 绑定属性v-bind:src,简写 :src 只绑定一次使用v-once,将绑定内容转义成html使用v-html
基本知识:
vue
$www.baidu.com/s?wd=' + this.content); this.content = ''; } this.$sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=' + this.content, { jsonp: 'cb' }).then(function(res) { this.myData = res.data.s; }, function() { alert("搜索失败"); }) }, changeDown: function() { this.now++; if(this.now == this.myData.length) { this.now = -1; } // 这里实现输入框中也显示同样的内容 this.content = this.myData[this.now]; }, changeUp: function() { this.now--; if (this.now == -2) { this.now = this.myData.length; } this.content = this.myData[this.now]; } }, }) } </script>
三个方法:get()用于对百度进行数据交互;cheangeDown()用于实现选中区域下移;changeUp()用于实现选中区域上移
HTML
<body> <div id="box"> <input type="text" name="" id="" v-model="content" @keyup="get($event)" @keydown.down="changeDown()" @keydown.up="changeUp()"> <ul> <!-- 这里注意给class添加属性的时候采用的是{属性:true/false}的形式 --> <li v-for="(item, index) in myData" :class="{grey: index==now}"> {{item}} </li> </ul> <p v-show="myData.length == 0">暂无数据...</p> </div> </body>
效果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。
本文共计535个文字,预计阅读时间需要3分钟。
概述+学习Vue的第二节,由于2.0版本不再向下兼容,视频中的不少内容不能实现。以下列出一些主要知识点:/\/v-on可简写为@/事件冒泡是指点击div内部的button时触发show1()函数,自然会冒泡到点击div内部。
简述
学习vue的第二节,由于2.0版本并不向下兼容,视频中的不少内不能实现。下面列出一些主要知识点
// v-on 可简写为@ // 事件冒泡是指当点击div内部的button触发show1()时,必然会冒泡到div上执行show2(),这才层级div中很常见 // 阻止冒泡,原生js法,设置事件对象的cancelBubble属性为true // vue方法@click.stop // 阻止默认行为,原生js法,设置事件对象的preventDefault属性为true // vue方法@contextmenu.prevent // 键盘事件获取键码,原生js法,使用事件对象的keyCode属性 // vue方法@keyup.键码或键名,如获取按下回车@keydown.13 或 @keydown.enter // 绑定属性v-bind:src,简写 :src 只绑定一次使用v-once,将绑定内容转义成html使用v-html
基本知识:
vue
$www.baidu.com/s?wd=' + this.content); this.content = ''; } this.$sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=' + this.content, { jsonp: 'cb' }).then(function(res) { this.myData = res.data.s; }, function() { alert("搜索失败"); }) }, changeDown: function() { this.now++; if(this.now == this.myData.length) { this.now = -1; } // 这里实现输入框中也显示同样的内容 this.content = this.myData[this.now]; }, changeUp: function() { this.now--; if (this.now == -2) { this.now = this.myData.length; } this.content = this.myData[this.now]; } }, }) } </script>
三个方法:get()用于对百度进行数据交互;cheangeDown()用于实现选中区域下移;changeUp()用于实现选中区域上移
HTML
<body> <div id="box"> <input type="text" name="" id="" v-model="content" @keyup="get($event)" @keydown.down="changeDown()" @keydown.up="changeUp()"> <ul> <!-- 这里注意给class添加属性的时候采用的是{属性:true/false}的形式 --> <li v-for="(item, index) in myData" :class="{grey: index==now}"> {{item}} </li> </ul> <p v-show="myData.length == 0">暂无数据...</p> </div> </body>
效果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

