Home  >  Article  >  Web Front-end  >  An article explaining in detail Vue+flex layout to implement TV end city list

An article explaining in detail Vue+flex layout to implement TV end city list

藏色散人
藏色散人forward
2023-01-20 14:33:241670browse

This article brings you relevant knowledge about Vue layout. It mainly summarizes and introduces how Vue uses flex layout to achieve the TV-end city list effect. It is very comprehensive and detailed. Let’s take a look at it together. I hope Help those in need.

Vue uses flex layout to implement city list on TV

City list and search are very common in vue. This blog will talk about how to implement search and search. City list

1. Implement search layout code:

<div class="search-bar">
  <input class="search-input" v-model="citySearchResult" :placeholder="searchDefault" :key="searchTitle"
         @endEditing="endEditing" :focusable="true" ref="searchInput" :duplicateParentState="true"
         :enableFocusBorder="true"/>
  <img  class="index-root-search-image-view-css" :src="searchIcon" alt="An article explaining in detail Vue+flex layout to implement TV end city list" >
  <span class="index-root-search-text-view-css" ref="textViewCity">{{searchDefaultKeyWord}}</span>
</div>

2. Search layout css style code:

.search-bar-root {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 140px;
}.index-root-search-title-css {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 40px;
}.search-bar-root .search-bar {
  background-color: #ffffff;
  width: 1000px;
  height: 100px;
  display: flex;
  justify-content: center;
  border-radius: 8px;
}.search-input {
  width: 780px;
  border-radius: 8px;
  font-size: 36px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #000000;
  margin-left: 40px;
  text-indent: 40px;
}.index-root-search-image-view-css {
  position: absolute;
  width: 32px;
  height: 32px;
  top: 35px;
  bottom: 35px;
  right: 0;
  margin-right: 102px;
  text-align: center;
}.index-root-search-flex-view-css {
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  width: 1450px;
  margin-left: 245px;
  margin-right: 245px;
  margin-top: 40px;
}.index-root-search-text-view-css {
  font-size: 30px;
  font-family: PingFangSC-Regular, PingFang SC;
  color: #000000;
  text-align: center;
  font-weight: 400;
  top: 0;
  bottom: 0;
  right: 0;
  position: absolute;
  margin-right: 30px;
}.index-root-search-title-text-view-css {
  font-size: 70px;
  font-family: PingFangSC-Regular, PingFang SC;
  color: #ffffff;
  text-align: center;
  opacity: 1.0;
}.search-city-button-view-css {
  width: 270px;
  height: 100px;
  background-color: rgba(0, 0, 0, .1);
  margin-right: 20px;
  margin-top: 40px;
  border-radius: 11px;
  border-width: 2px;
  border-color: rgba(255, 255, 255, 0.1);
  focus-background-color: #fff;
}.search-city-button-view-css .city-sel-box {
  border-width: 2px;
  border-color: #32C5FF;
}

3. City list layout code:

<div>
  <div>
    <div>
      <img  alt="An article explaining in detail Vue+flex layout to implement TV end city list" >
      <img  alt="An article explaining in detail Vue+flex layout to implement TV end city list" >
    </div>
    <span>{{item.cityName}}</span>
  </div>
<p><strong>4. City list css style code: </strong></p>
<pre class="brush:php;toolbar:false">.index-root-search-flex-view-css {
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  width: 1450px;
  margin-left: 245px;
  margin-right: 245px;
  margin-top: 40px;
}.index-root-search-text-view-css {
  font-size: 30px;
  font-family: PingFangSC-Regular, PingFang SC;
  color: #000000;
  text-align: center;
  font-weight: 400;
  top: 0;
  bottom: 0;
  right: 0;
  position: absolute;
  margin-right: 30px;
}.index-root-search-title-text-view-css {
  font-size: 70px;
  font-family: PingFangSC-Regular, PingFang SC;
  color: #ffffff;
  text-align: center;
  opacity: 1.0;
}.search-city-button-view-css {
  width: 270px;
  height: 100px;
  background-color: rgba(0, 0, 0, .1);
  margin-right: 20px;
  margin-top: 40px;
  border-radius: 11px;
  border-width: 2px;
  border-color: rgba(255, 255, 255, 0.1);
  focus-background-color: #fff;
}.search-city-button-view-css .city-sel-box {
  border-width: 2px;
  border-color: #32C5FF;
}.icon-location-reactive {
  position: absolute;
  width: 26px;
  height: 34px;
  margin-left: 60px;
  margin-top: 30px;
  margin-bottom: 30px;
}.icon-location {
  width: 26px;
  height: 34px;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 9;
}.search-city-hot-text-iew-css {
  width: 270px;
  height: 100px;
  background-color: rgba(50, 197, 255, 0.1);
  border-radius: 11px;
  border: 2px solid #32C5FF;
  font-size: 36px;
  font-family: PingFangSC-Regular, PingFang SC;
  text-align: center;
  color: white;
}.search-city-empty {
  margin-top: 40px;
  width: 425px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  margin-left: 535px;
}.search-city-empty .icon-no-connect {
  width: 425px;
  height: 307px;
}.search-city-empty .empty-txt {
  font-size: 32px;
  font-family: PingFangSC-Light, PingFang SC;
  font-weight: 300;
  color: #FFFFFF;
  margin-top: 60px;
}

5. City list gets focus Event:

Mainly set in div: focusable="true" and @focus="onFocus"

<div>
          <div>
            <img  alt="An article explaining in detail Vue+flex layout to implement TV end city list" >
            <img  alt="An article explaining in detail Vue+flex layout to implement TV end city list" >
 </div>
<p><strong>6. Set focus background color and font effect:</strong></p>
<p> Mainly set: duplicateParentState="true" When the text gets focus, the color will not be affected by the parent layout. You can also set focus magnification and border effects </p>
<pre class="brush:php;toolbar:false">:enableFocusBorder="true"//设置获得焦点时的边框
:focusScale="1.0"//设置焦点放大时的倍数

Focus effect style: :style="{focusColor: focusHotTextColor,fontSize: textFontSize,fontWeight: textFontWeight,}

<span>{{item.cityName}}</span>

7. Search box input event:

//输入内容之后请求城市列表接口刷新数据
endEditing(e) {
  console.log("--resultData--", this.citySearchResult)
},

8. The event when the search box gets focus:

onFocus(e) {
  this.focused = e.isFocused;
  this.$emit("onButtonFocused", e.isFocused);
},

9. The TV soft keyboard pops up by default:

mounted() {
  this.hotCity = hotCity;
  this.showHot = true;
  this.pageLoading = true
  //弹出软键盘
  this.$refs.searchInput.focus()
  //搜索框默认获取焦点
  this.setHideLoading()
},

10. The complete code is as follows:

<script>import searchImage from "@/assets/search_focus.png";import searchBackGroundImage from "@/assets/index-bg-qing.jpg";import {hotCity} from &#39;@/views/contsants&#39;;import {ESLaunchManager} from "@extscreen/es-core";export default {
  name: "city_list",
  props: {
    searchKeyWord: {
      type: String,
      default: &#39;&#39;,
    },
    focusTextColor: {
      type: String,
      default: &#39;#000000&#39;
    },
    focusHotTextColor: {
      type: String,
      default: &#39;#00EFFF&#39;
    },
    textColor: {
      type: String,
      default: &#39;#FFFFFF&#39;
    },
    textFontSize: {
      type: String,
      default: &#39;30px&#39;
    },
    textFontWeight: {
      type: Number,
      default: 400
    },
    focusBackground: {
      orientation: &#39;TL_BR&#39;,//TOP_BOTTOM,TR_BL, RIGHT_LEFT, BR_TL, BOTTOM_TOP,BL_TR,LEFT_RIGHT,TL_BR,
      cornerRadius: [40, 40, 40, 40],
      normal: [&#39;#00000000&#39;, &#39;#00000000&#39;],
      focused: [&#39;#F5F5F5&#39;, &#39;#F5F5F5&#39;],
    },
  },
  data() {
    return {
      pageLoading: false,
      text: &#39;search city&#39;,
      search: &#39;&#39;,
      searchIcon: searchImage,
      searchImageData: searchBackGroundImage,
      searchTitle: "切换城市",
      searchDefaultKeyWord: &#39;搜索&#39;,
      searchDefault: &#39;请输入城市名称首字母或全拼&#39;,
      focusColor: &#39;#f5f5f5&#39;,
      citySearchResult: "",
      hotCity: [],
      cityName: "",
      cityId: "",
      showHot: true,
      params: &#39;&#39;,
    }
  },
  activated() {
  },
  deactivated() {
    this.resetModel()
  },
  mounted() {
    this.hotCity = hotCity;
    this.showHot = true;
    this.pageLoading = true
    //弹出软键盘
    this.$refs.searchInput.focus()
    //搜索框默认获取焦点
    this.setHideLoading()
  },
  methods: {
    setHideLoading() {
      setTimeout(() => {
        this.pageLoading = false
      }, 500)
    },
    onFocus(e) {
      this.focused = e.isFocused;
      this.$emit("onButtonFocused", e.isFocused);
    },
    //输入内容之后请求城市
    endEditing(e) {
      console.log("--resultData--", this.citySearchResult)
    },
    onBackPressed() {
      ESLaunchManager.finishESPage();
    },
    resetModel() {
      this.citySearchResult = "";
      this.hotCity = [];
      this.pageLoading = false;
      this.searchTitle = "";
      this.searchDefaultKeyWord = "";
      this.searchDefault = "";
    },
  }
}</script>

11. The screenshot of the effect achieved is as follows:

An article explaining in detail Vue+flex layout to implement TV end city list

An article explaining in detail Vue+flex layout to implement TV end city list

Related recommendations: vuejs video tutorial

The above is the detailed content of An article explaining in detail Vue+flex layout to implement TV end city list. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.im. If there is any infringement, please contact admin@php.cn delete
Previous article:An article briefly analyzing the single file component in VueNext article:An article briefly analyzing the single file component in Vue

Related articles

See more