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

關(guān)于vue跳轉(zhuǎn)后頁面置頂?shù)膯栴}

 更新時間:2022年05月26日 10:31:29   作者:elephant230  
這篇文章主要介紹了關(guān)于vue跳轉(zhuǎn)后頁面置頂?shù)膯栴},具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

vue跳轉(zhuǎn)后頁面置頂

今天測試指出我的項目跳轉(zhuǎn)頁面時未置頂,嗯,這個太影響用戶體驗了。

但是辦法總會有噠!No Problem!

只需在路徑上匹配一段關(guān)于scroll方法即可,

我簡單截取一段我的代碼以作演示:

或者使用這段代碼:

afterEach (to, from, next) {
    window.scrollTo(0, 0)
}

但是還有個問題依舊沒有徹底克服!

比如,如果當前頁面是首頁,點擊頁面中的"首頁"選項后,卻依然不置頂,那么只能老老實實的增加個回到頂部了。

 toYpWebsite () {
      // this.$router.push('/ypWebsite')
      document.body.scrollTop = document.documentElement.scrollTop = 0
 },

document.body.scrollTop = document.documentElement.scrollTop = 0

這兩條就可以解決關(guān)于頁面置頂?shù)膯栴},哈哈,測試沒轍了!

vue如何實現(xiàn)置頂

new.json 數(shù)據(jù)代碼:

[
  {"id": "G11111","title": "手機","price": 2999},
  {"id": "G22222","title": "平板電腦","price": 1999},
  {"id": "G33333","title": "筆記本電腦","price": 5999},
  {"id": "G44444","title": "樹莓派電腦","price": 999},
  {"id": "G55555","title": "超級計算機","price": 9999999}
]

具體代碼如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
    <script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
</head>
<body>
<div id="app">
    <ul >
        <li v-for="(pr,index) in info" :key="index">{{ pr.id }} {{pr.title}} ¥{{pr.price}}
            <button @click="aaa(pr,index)">{{hello}}</button>
        </li>
    </ul>
</div>
<script type = "text/javascript">
    
    new Vue({
        el: '#app',
        data () {
            return {
                info: null,
                hello:"置頂",
                new:"new.json"
            }
        },
        mounted () {
            axios.get(this.new)
                .then(response => {
                    this.info = response.data;
                    console.log(response.data);
                    for (let i=0;i<this.info.length;i++){
                        console.log(this.info[i].title);
                        if (this.info[i].id == "G33333" || this.info[i].id == "G44444"){
                            this.info.unshift(this.info[i]); //把查找到的數(shù)據(jù)復制添加到數(shù)組的首位
                            this.info.splice(i+1,1); //數(shù)據(jù)復制添加到數(shù)組的首位后,原本查找的數(shù)據(jù)位置會發(fā)生改變,所以要往后加一位(i+1),然后刪除它
                        }
                    }
                })
                .catch(error=> {
                    console.log(error);
                    console.log("%c404:"+this.new+"數(shù)據(jù)請求失?。。?!", "color:red;font-size:30px;");
                })
        },
        methods:{
            aaa:function (pr,index) {
                this.info.splice(index,1);
                this.info.unshift(pr);
            }
        }
    })
</script>
</body>
</html>

效果圖如下:

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

波密县| 和田县| 大关县| 阿克陶县| 辉县市| 长汀县| 和平县| 海南省| 乌拉特中旗| 邓州市| 连州市| 东海县| 新田县| 宁海县| 天门市| 沙雅县| 尚志市| 贵阳市| 河曲县| 江源县| 蒙阴县| 皮山县| 福泉市| 关岭| 开远市| 观塘区| 普陀区| 德清县| 固原市| 凉城县| 浪卡子县| 甘孜| 山东| 嘉祥县| 吉安市| 苍南县| 江华| 浦县| 瑞安市| 皋兰县| 渑池县|