【发布时间】:2019-03-27 08:17:47
【问题描述】:
我在<li> 元素中组织了链接。在点击事件中,我将页面的 URL 更改为页面中对应的 <div> id 元素。
现在,我正在寻找一种方法来触发makeIt() 中的输入按下事件,以便滚动到相关的<div> 元素。
这是我的代码:
<template>
<div>
<div style="margin-top: 50px;"></div>
<div style="margin-bottom: 50px;">
<ul>
<li
v-for="i in 3"
:key="i"
@click="makeIt(i)"
>
Link{{ i }}
</li>
</ul>
</div>
<div
v-for="i in 3"
:id="i"
:class="`div${i}`"
>
Div {{ i }}
</div>
</div>
</template>
<script>
export default {
methods: {
makeIt(hashbang) {
this.$router.push(`#${hashbang}`)
}
}
}
</script>
<style>
.div1 {
background-color: red;
height: 600px;
}
.div2 {
background-color: blue;
height: 500px;
}
.div3 {
background-color: yellow;
height: 500px;
}
</style>
如何实现这个目标?
【问题讨论】:
标签: javascript vue.js nuxt.js