vue 响应式ui

Are you thinking of building something awesome with one of the popular modern frameworks out there right now, but don’t know how to get started?

您是否正在考虑使用当前流行的现代框架之一来构建出色的东西,但不知道如何入门?

If yes, then this post will help you get a kick started and build something awesome.

如果是的话,那么这篇文章将帮助您入门并建立一些很棒的东西。

What are we going to build?

我们要建造什么?

We will be building a responsive client side search of the 7 wonders of the world with the following features:

我们将通过以下功能对世界7大奇观进行响应式客户端搜索:

  1. Text Search & Filters based on Ratings and Likes.

    基于评级和喜欢的文本搜索过滤器

  2. 2 items per row for Tablet and Desktop, 1 item per row for Mobile.

    平板电脑台式机每行2项, 移动设备每行1项。

  3. Fetching data asynchronously from external API on client side.从客户端的外部API异步获取数据。
  4. Responsive view as shown below:响应视图如下图:

Live Demo: https://vue-responsive-search.herokuapp.com

现场演示 : https : //vue-sensitive-search.herokuapp.com

Source Code: https://github.com/honey93/VueSearchExample

源代码 : https : //github.com/honey93/VueSearchExample

科技架构 (Tech Architecture)

We will be working with the following technologies:

我们将使用以下技术:

  1. Vue.js: The Progressive JavaScript Framework

    Vue.js 渐进式JavaScript框架

  2. BootstrapVue: It provides one of the most comprehensive implementations of Bootstrap V4 components and grid system available for Vue.js 2.5+, complete with extensive and automated WAI-ARIA accessibility markup.

    BootstrapVue 它提供了适用于Vue.js 2.5+的Bootstrap V4组件和网格系统的最全面的实现之一,并带有大量且自动的WAI-ARIA可访问性标记。

  3. Vue Cli 3: Standard Tooling for Vue.js Development

    Vue Cli 3 用于Vue.js开发的标准工具

项目结构 (Project Structure)

To get started with our Vue project, we need to setup many things like Vue, Bootstrap, Vue Router, Vuex, etc.

要开始我们的Vue项目,我们需要设置许多东西,例如Vue,Bootstrap,Vue Router,Vuex等。

Vue Cli provides us the command to create the project with most of the needed configurations.

Vue Cli向我们提供了使用大多数所需配置来创建项目的命令。

npm install -g @vue/cli
vue create project-name

For the remaining things like BootstrapVue, vue-star-rating, etc, we can use the npm install command.

对于BootstrapVue,vue-star-rating等其余内容,我们可以使用npm install命令。

The default project created using vuecli has the following structure:

使用vuecli创建的默认项目具有以下结构:

/Root Folder Public/src/assets/  /* Static assets like images goes here */components/ /* Small part of a view */views/  /* View represents a page composed of several components*/App.vue /* The main view inside which the routing logic goes */main.js  /* App initialisation happens here  */router.js /* Router logic is defined here */store.js /* Optional state management library Vuex */package.json /* It consist of all the dependencies of the project. */......

The above things are there to explain the project architecture to you and the way to initialise it.

以上是向您解释项目架构以及初始化方式的内容。

We can get started by cloning the repository and writing the following commands:

我们可以通过克隆存储库并编写以下命令来开始使用:

npm install
npm run serve

Some important components explained:

一些重要的组件进行了解释:

components/Header.vue

组件/Header.vue

The header has been created in the form of a single independent component so that it can be reused across pages, avoiding duplication of the code.

标头以单个独立组件的形式创建,因此可以在页面之间重用,从而避免了代码重复。

/* Vue style of writing component: template, script and style*/
<template><div class="pad-15-hor pad-15-ver header"><div><img src="@/assets/logo.png" width="25px"> Responsive Search</div><div><i class="fas fa-bars"></i></div></div>
</template>
<script>
export default {name: "Header"
};
</script>
<style scoped>
.header {display: flex;flex-flow: row wrap;justify-content: space-between;
}
</style>

components/Main.vue

组件/Main.vue

This component consist of the entire logic of search / filters and display of results fetched from the API.

此组件包含搜索/过滤器的整个逻辑以及从API提取的结果的显示。

This component is using the above Header by importing it in the script.

该组件通过将其导入脚本中来使用上述标题。

<template><div><Header/><div class="pad-15-hor pad-15-ver search-parent"><div class="search-bar"><b-form-input@input="search_text()"v-model="search.text"type="text"placeholder="Search by Name"></b-form-input><span class="search-icon"><i class="fas fa-search"></i></span></div><div><span class="bold">Total Likes:</span>{{likes.count}}<span class="bold">Hits:</span>{{likes.hit}}</div><div><b-form-select @input="sort()" v-model="search.filter" :options="options"/></div></div>
<div class="container-fluid"><div class="row"><div class="col-md-6 pad-15-ver" v-for="wonder in wonders_data" :key="wonder.id"><divclass="card-inner"@mouseover="show_hover(true,wonder.id)"@mouseout="show_hover(false,0)"><img class="card-img" :src="wonder.imageURL">
<div class="card-bottom pad-15-hor" v-show="!hover_flag || active_id != wonder.id"><div class="min-width-160"><span class="bold">Ratings:</span><star-rating:rating="wonder.ratings":show-rating="false":inline="true":star-size="15"></star-rating></div><div class="max-width-160"><span class="bold">{{wonder.place}}</span></div></div>
<div :class="{'card-hover':1}" v-show="hover_flag && active_id == wonder.id"><span@click="make_active(wonder.id)":class="{'fas':1, 'fa-heart':1, 'absolute-star':1, 'green':check_active(wonder.id)}">{{wonder.likes}}</span><h5>{{wonder.place}}</h5><p>{{wonder.description}}</p></div></div></div></div></div></div>
</template>
<script>
/* Importing Header to use in this component */
import Header from "@/components/Header.vue";
/* Importing axios for async REST calls */
import axios from "axios";
export default {name: "Main",
/* mounted gets called when the component gets mounted. AJAX calls are preferred in mounted lifecycle method */mounted() {this.hover_flag = false;
var inside = this;
axios.get("https://www.mocky.io/v2/5c7b98562f0000c013e59f07").then(function(response) {//console.log(response);
inside.wonders_data_actual = response.data.data;
response.data.data.map(function(wonder) {inside.likes.count += wonder.likes;});
inside.wonders_data_actual = inside.wonders_data_actual.map(function(wonder) {wonder.active_like = false;return wonder;});inside.wonders_data = response.data.data;}).catch(function(error) {// console.log(error);});},
/* All the data variable declaration are done here:  */data() {return {hover_flag: false,wonders_data_actual: [],wonders_data: [],active_id: 0,options: [{ value: null, text: "Sort By" },{ value: "a", text: "Ratings" },{ value: "b", text: "Likes" }],search: { filter: null, text: "" },likes: { count: 0, hit: 0 }};},
/* Methods are defined here */methods: {show_hover(flag, active_id) {this.hover_flag = flag;this.active_id = active_id;},sort() {//console.log(this.search.filter);this.search.filter == "b"? this.wonders_data.sort(function(a, b) {return b.likes - a.likes;}): this.wonders_data.sort(function(a, b) {return b.ratings - a.ratings;});},search_text() {//console.log(this.search.text);
var inside = this;
this.wonders_data = this.wonders_data_actual.filter(function(wonder) {if (wonder.place.toLowerCase().indexOf(inside.search.text.toLowerCase()) != "-1") {return wonder;}});},check_active(id) {var flag = false;this.wonders_data_actual.map(function(wonder) {if (wonder.id == id) {flag = wonder.active_like;}});return flag;},make_active(id) {this.likes.hit++;this.wonders_data_actual = this.wonders_data_actual.map(function(wonder) {if (wonder.id == id) {wonder.active_like = !wonder.active_like;wonder.active_like ? wonder.likes++ : wonder.likes--;}
return wonder;});var inside = this;
inside.likes.count = 0;this.wonders_data_actual.map(function(wonder) {inside.likes.count += wonder.likes;});}},components: {Header}
};
</script>
<style scoped> /* Styles are scoped to this component only.*/
/* Style for Desktop/Tablet  */
.search-parent {display: flex;flex-flow: row wrap;justify-content: space-between;background-color: lightgray;
}
.card-inner {position: relative;overflow: hidden;box-shadow: 2px 2px 8px grey;
}
.card-img {width: 100%;
}
.card-bottom {position: absolute;bottom: 0;left: 0;height: 30px;width: 100%;background-color: white;opacity: 0.7;display: flex;justify-content: space-between;
}
.card-hover {position: absolute;right: 15px;left: 15px;top: 15px;bottom: 15px;background-color: white;opacity: 0.7;display: flex;flex-flow: column wrap;justify-content: center;align-items: center;
}
.absolute-star {position: absolute;top: 10px;right: 10px;
}
.card-hover p {font-size: 10px;text-align: center;
}
.bold {font-weight: 500;
}
.rating-div {width: 200px;
}
.search-bar {position: relative;
}
.search-bar input {padding-left: 30px;
}
.search-icon {position: absolute;top: 8px;left: 8px;
}
/* For Mobile Device, we will be going with column wrap approach */
@media screen and (max-width: 550px) {.search-parent {display: flex;flex-flow: column wrap;justify-content: center;align-items: center;background-color: lightgray;}
.search-parent div {width: 100%;text-align: center;}
}
</style>

I hope you have a better understanding of how to get started with Vue and create something awesome.

我希望您对如何开始使用Vue并创建很棒的东西有更好的了解。

If you found this helpful, clap below, give stars to the project repo and share with your friends too.

如果您觉得有帮助,请在下面一下,给项目回购加注 星号 ,并与您的朋友分享。

翻译自: https://www.freecodecamp.org/news/how-to-set-up-responsive-ui-search-in-vue-js-bf6007b7fc0f/

vue 响应式ui

vue 响应式ui_如何在Vue.js中设置响应式UI搜索相关推荐

  1. 如何在node.js中发出HTTP POST请求?

    如何在node.js中使用数据发出出站HTTP POST请求? #1楼 如果您使用请求库,这会变得更容易. var request = require('request');request.post( ...

  2. 如何在Tensorflow.js中处理MNIST图像数据

    by Kevin Scott 凯文·斯科特(Kevin Scott) 如何在Tensorflow.js中处理MNIST图像数据 (How to deal with MNIST image data i ...

  3. 如何在Node.js中打印堆栈跟踪?

    本文翻译自:How to print a stack trace in Node.js? 有谁知道如何在Node.js中打印堆栈跟踪? #1楼 参考:https://stackoom.com/ques ...

  4. 如何在Node.js中获取本机本地IP地址

    最近在做Cloud related的项目时,遇到一个问题,就是如何在Node.js中获取本机的IP地址.Node.js提供的API中,只能获取本机的hostname. os = require('os ...

  5. java怎么让表格的字段相乘,excel表格怎么让数据相乘-如何在excel表格中设置乘法公式...

    EXCEL里的表格使两列自动相乘怎么设置? 在你需要得出结果的那个单元格,输入"=",再点击你需要相乘的第一个单元格,再输入"*",再点击你需要相乘的第二个单元 ...

  6. Android如何在java代码中设置margin

    Android如何在java代码中设置margin,也就是组件与组件之间的间距. 代码中设置: LinearLayout.LayoutParams params = new LinearLayout. ...

  7. 如何在 Windows XP 中设置、查看、更改或删除文件和文件夹的特殊权限

    为什么80%的码农都做不了架构师?>>>    文章编号: 308419 - 最后修改: 2005年10月24日 - 修订: 3.1 如何在 Windows XP 中设置.查看.更改 ...

  8. html设置粗体字,如何在HTML输出中设置粗体字段

    以下是我的PowerShell脚本.它会生成一个格式良好的HTML表格.我想将一列加粗(Full%列).我不能为了我的生活想到一个办法.如何在HTML输出中设置粗体字段 我试过在不同的地方插入粗体标签 ...

  9. 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作...

    Phpstorm除了能直接打开localhost文件之外,还可以连接FTP,除了完成正常的数据传递任务之外,还可以进行本地文件与服务端文件 的异同比较,同一文件自动匹配目录上传,下载,这些功能是平常I ...

最新文章

  1. SAP S4HANA 实战LTMC - 打响了第一炮
  2. 解释i节点在文件系统中的作用?超级块作用?
  3. 今天开始学模式识别与机器学习Pattern Recognition and Machine Learning 书,章节1.1,多项式曲线拟合(Polynomial Curve Fitting)
  4. 深度学习与概率、统计的有趣探讨
  5. C和C++线性表的链式存储
  6. 集合python_python集合访问的方法
  7. Python_内置模块2
  8. VMware 设置网络
  9. 199. Binary Tree Right Side View
  10. uniapp uView u-picker组件三级联动Demo
  11. 【Luogu】重返现世
  12. linux环境编程apue,《UNIX环境高级编程》中apue.h的问题
  13. 苹果cms播放器html,苹果cms 全局播放器dplayer带后台Dplayer播放器苹果CMSV10插件
  14. 互联网快讯:粉笔科技布局线下打造双核驱动;极米产品获用户青睐;迅雷发布2021年财报;荣耀Magic4系列国内发布
  15. python-求两个数的最小公倍数
  16. 雅思阅读真经总纲_雅思阅读用哪本书?五大热门雅思阅读书籍全面点评
  17. php连接外卖打印机,javaScript 连接打印机,打印小票实例分享
  18. [转] C++中字符型变量的地址输出
  19. 极米Z7X对比当贝D5X区别 哪个值得买
  20. 工作笔记:如何用Django连接Kerberized甲骨文(Oracle)数据库

热门文章

  1. STL源码剖析面试问题
  2. Java最新大厂面试真题总结,瞬间高大上了!
  3. 搞懂开源框架设计思想真的这么重要吗?终获offer
  4. [JS 分析] 天_眼_查 字体文件
  5. mysql复制主从集群搭建
  6. linux命令-vim命令模式
  7. php实现当前用户在线人数
  8. ASP.NET N问N答 (一) ASP.NET怎么导出到WORD?(把girdview里面的数据到出到word)
  9. Python打印杨辉三角形 RUNOOB python练习题61
  10. 自己动手写事件总线(EventBus)