最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解Vue項(xiàng)目中實(shí)現(xiàn)錨點(diǎn)定位

 更新時(shí)間:2019年04月24日 14:42:10   作者:機(jī)智的導(dǎo)演  
這篇文章主要介紹了Vue項(xiàng)目中實(shí)現(xiàn)錨點(diǎn)定位,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

背景

今天在開發(fā)限時(shí)練-提分加項(xiàng)目的時(shí)候,有一個(gè)需要錨點(diǎn)定位的需求,而在Vue項(xiàng)目中,使用傳統(tǒng)的在a標(biāo)簽的href屬性中寫id的方法無效,會(huì)導(dǎo)致瀏覽器的地址改變從而跳轉(zhuǎn)到其他頁面。

解決

最終參考vue2.0中怎么做錨點(diǎn)定位改問題下的回答實(shí)現(xiàn)了效果。

<template>
<div class="score-preview-container">
 <div class="content-box">
 <div class="content-page-box">
  <GlobalAnalysis :id="#anchor-0" />
  <ErrorMerge :id="#anchor-1" />
  <DoExercise :id="#anchor-2" />
 </div>
 <div class="nav-button-box">
  <span class="nav-button-fix">
  <div class="nav-button" v-for="(item,index) in buttonArr" :key="index" :class="{active : activeBtn == index}" @click="goAnchor('#anchor-'+index,index)">{{item}}</div>
  </span>
 </div>
 </div>
</div>
</template>

<script>
import { mapActions } from "vuex";
import GlobalAnalysis from "./components/GlobalAnalysis.vue";
import ErrorMerge from "./components/ErrorMerge.vue";
import DoExercise from "./components/DoExercise.vue";
export default {
 name: "score-preview",
 components: { GlobalAnalysis, ErrorMerge, DoExercise },
 data() {
 return {
  buttonArr: ["整體分析", "錯(cuò)題整理", "提分訓(xùn)練"],
  activeBtn: 0
 };
 },
 mounted() {
 this.dataInit();
 },
 methods: {
 ...mapActions("v2-score-preview", [
  "fetchClassScoreData",
  "fetchPersonalReportData",
  "fetchErrorQuestionData",
  "fetchExerciseData"
 ]),
 //初始化
 dataInit() {
  this.fetchClassScoreData();
  this.fetchPersonalReportData();
  this.fetchErrorQuestionData();
  this.fetchExerciseData();
 },
 //錨點(diǎn)跳轉(zhuǎn)
 goAnchor(selector, index) {
  this.activeBtn = index;
  document.querySelector("#app-root").scrollTop = this.$el.querySelector(selector).offsetTop;
 }
 }
};
</script>

另外,參考頁面內(nèi)錨點(diǎn)定位及跳轉(zhuǎn)方法總結(jié)文章中的第四種方法,發(fā)現(xiàn)使用scrollIntoView()方法也能實(shí)現(xiàn)錨點(diǎn)定位的效果。

//錨點(diǎn)跳轉(zhuǎn)
goAnchor(selector, index) {
 this.activeBtn = index;
 this.$el.querySelector(selector).scrollIntoView()
}

以上所述是小編給大家介紹的Vue項(xiàng)目中實(shí)現(xiàn)錨點(diǎn)定位詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

平果县| 清水县| 和硕县| 乐陵市| 自治县| 伽师县| 吴旗县| 阜平县| 定西市| 长沙县| 布拖县| 乐陵市| 慈溪市| 永胜县| 湛江市| 门头沟区| 兴业县| 卢湾区| 凉城县| 崇阳县| 星座| 巩留县| 东明县| 宜良县| 周宁县| 东安县| 古蔺县| 和平区| 曲周县| 东乌珠穆沁旗| 天水市| 三门县| 永州市| 玉环县| 井陉县| 九台市| 左贡县| 巩义市| 辽阳县| 尼勒克县| 日土县|