如何制作自动滚动到某个部分的参数

how to make params that automatically scrolls to a section

我想要一条这样的路线

http://localhost:8080/help/category/newuser#1

因此,我将其写在我的模板中

<router-link
   v-bind:to="{
   name: 'help',
   params: { id: selectedCategory+'#'+eachQuestion.id },
   }"
>

但这不起作用并导致

http://localhost:8080/help/category/newuser%231

所以 # 变成 %23。如何解决这个问题?谢谢!

您可以通过将参数名称作为对象传递到带有参数的路由:

params: { category: selectedCategory }

如果您还传递了一个 hash 值,您也可以声明 hash 属性:

hash: eachQuestion.id