vue 響應式ui_如何在Vue.js中設置響應式UI搜索

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/392002.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392002.shtml
英文地址,請注明出處:http://en.pswp.cn/news/392002.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

蘭州交通大學計算機科學與技術學院,蘭州交通大學

信息與計算科學專業依托數學和計算機科學與技術兩個一級學科碩士學位授予點&#xff0c;運籌學與控制論、計算機科學與技術兩個省級重點學科&#xff0c;培養理工融合、學科交叉的創新性人才。自2008年以來&#xff0c;承擔國家自然科學基金10余項&#xff0c;發表SCI收錄雜志論…

leetcode 424. 替換后的最長重復字符(滑動窗口)

給你一個僅由大寫英文字母組成的字符串&#xff0c;你可以將任意位置上的字符替換成另外的字符&#xff0c;總共可最多替換 k 次。在執行上述操作后&#xff0c;找到包含重復字母的最長子串的長度。 注意&#xff1a;字符串長度 和 k 不會超過 104。 示例 1&#xff1a; 輸入…

javascript放在head和body的區別(w3c建議放在head標簽中)

JavaScript腳本放在哪里 在HTML body部分中的JavaScripts會在頁面加載的時候被執行。 在HTML head部分中的JavaScripts會在被調用的時候才執行。—————————————————————————— JavaScript應放在哪里 頁面中的JavaScripts會在瀏覽器加載頁面的時候被立即…

jQuery事件整合

一、jQuery事件 1、focus&#xff08;&#xff09;元素獲得焦點 2、blur&#xff08;&#xff09;元素失去焦點 3、change&#xff08;&#xff09; 表單元素的值發生變化&#xff08;可用于驗證用戶名是否存在&#xff09; 4、click&#xff08;&#xff09; 鼠標單擊 5、dbc…

tableau跨庫創建并集_刮擦柏林青年旅舍,并以此建立一個Tableau全景。

tableau跨庫創建并集One of the coolest things about making our personal project is the fact that we can explore topics of our own interest. On my case, I’ve had the chance to backpack around the world for more than a year between 2016–2017, and it was one…

策略模式下表單驗證

策略模式下表單驗證 class Validator {constructor(strategies) {this.cache []}add(value, rules) {if (!rules instanceof Array) throw rules should be Arrayvar self thisfor(var i 0, rule; rule rules[i];) {(function(rule) {var strategyArr rule.strategy.split…

在五分鐘內學習使用Python進行類型轉換

by PALAKOLLU SRI MANIKANTA通過PALAKOLLU SRI MANIKANTA 在五分鐘內學習使用Python進行類型轉換 (Learn typecasting in Python in five minutes) 以非常詳盡的方式介紹了Python中的類型轉換和類型轉換的速成課程 (A crash course on Typecasting and Type conversion in Pyt…

Ajax post HTML 405,Web API Ajax POST向返回 405方法不允許_jquery_開發99編程知識庫

因此&#xff0c;我有一個像這樣的jquery ajax請求&#xff1a;function createLokiAccount(someurl) {var d {"Jurisdiction":17}$.ajax({type:"POST",url:"http://myserver:111/Api/V1/Customers/CreateCustomer/",data: JSON.stringify(d),c…

leetcode 480. 滑動窗口中位數(堆+滑動窗口)

中位數是有序序列最中間的那個數。如果序列的大小是偶數&#xff0c;則沒有最中間的數&#xff1b;此時中位數是最中間的兩個數的平均數。 例如&#xff1a; [2,3,4]&#xff0c;中位數是 3 [2,3]&#xff0c;中位數是 (2 3) / 2 2.5 給你一個數組 nums&#xff0c;有一個大…

1.0 Hadoop的介紹、搭建、環境

HADOOP背景介紹 1.1 Hadoop產生背景 HADOOP最早起源于Nutch。Nutch的設計目標是構建一個大型的全網搜索引擎&#xff0c;包括網頁抓取、索引、查詢等功能&#xff0c;但隨著抓取網頁數量的增加&#xff0c;遇到了嚴重的可擴展性問題——如何解決數十億網頁的存儲和索引問題。20…

如何實現多維智能監控?--AI運維的實踐探索【一】

作者丨吳樹生&#xff1a;騰訊高級工程師&#xff0c;負責SNG大數據監控平臺建設。近十年監控系統開發經驗&#xff0c;具有構建基于大數據平臺的海量高可用分布式監控系統研發經驗。 導語&#xff1a;監控數據多維化后&#xff0c;帶來新的應用場景。SNG的哈勃多維監控平臺在完…

.Net Web開發技術棧

有很多朋友有的因為興趣&#xff0c;有的因為生計而走向了.Net中&#xff0c;有很多朋友想學&#xff0c;但是又不知道怎么學&#xff0c;學什么&#xff0c;怎么系統的學&#xff0c;為此我以我微薄之力總結歸納寫了一篇.Net web開發技術棧&#xff0c;以此幫助那些想學&#…

使用Python和MetaTrader在5分鐘內開始構建您的交易策略

In one of my last posts, I showed how to create graphics using the Plotly library. To do this, we import data from MetaTrader in a ‘raw’ way without automation. Today, we will learn how to automate this process and plot a heatmap graph of the correlation…

卷積神經網絡 手勢識別_如何構建識別手語手勢的卷積神經網絡

卷積神經網絡 手勢識別by Vagdevi Kommineni通過瓦格德維科米尼(Vagdevi Kommineni) 如何構建識別手語手勢的卷積神經網絡 (How to build a convolutional neural network that recognizes sign language gestures) Sign language has been a major boon for people who are h…

spring—第一個spring程序

1.導入依賴 <dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.0.9.RELEASE</version></dependency>2.寫一個接口和實現 public interface dao {public void save(); }…

請對比html與css的異同,css2與css3的區別是什么?

css主要有三個版本&#xff0c;分別是css1、css2、css3。css2使用的比較多&#xff0c;因為css1的屬性比較少&#xff0c;而css3有一些老式瀏覽器并不支持&#xff0c;所以大家在開發的時候主要還是使用css2。CSS1提供有關字體、顏色、位置和文本屬性的基本信息&#xff0c;該版…

基礎 之 數組

shell中的數組 array (1 2 3) array ([1]ins1 [2]ins2 [3]ins3)array ($(命令)) # 三種定義數組&#xff0c;直接定義&#xff0c;鍵值對&#xff0c;直接用命令做數組的值。${array[*]}${array[]}${array[0]} # 輸出數組中的0位置的值&#xff0c;*和…

Linux_異常_08_本機無法訪問虛擬機web等工程

這是因為防火墻的原因&#xff0c;把響應端口開啟就行了。 # Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m st…

Building a WAMP Dev Environment [3/4] - Installing and Configuring PHP

Moved to http://blog.tangcs.com/2008/10/27/wamp-installing-configuring-php/轉載于:https://www.cnblogs.com/WarrenTang/archive/2008/10/27/1320069.html

ipywidgets_未來價值和Ipywidgets

ipywidgetsHow to use Ipywidgets to visualize future value with different interest rates.如何使用Ipywidgets可視化不同利率下的未來價值。 There are some calculations that even being easy becoming better with a visualization of his terms. Moreover, the sooner…