简体   繁体   English

无法解析指令:滚动到 Vue-scrollto

[英]Failed to resolve directive: scroll-to Vue-scrollto

I am making a web application with Vue js(i am a newbie on vue js), specifically Vue 2.x.我正在使用 Vue js(我是 vue js 的新手)制作一个 Web 应用程序,特别是 Vue 2.x。 I want to click in an element of a menu, and then scroll to the that element.我想单击菜单元素,然后滚动到该元素。 I have thought to use this tool https://vue-scrollto.netlify.app/examples/ as it is exactly what i want to do.我曾想过使用这个工具https://vue-scrollto.netlify.app/examples/因为这正是我想要做的。

The problem is that when I repeat the same the code as in the examples, I receive the error " [Vue warn]: Failed to resolve directive: scroll-to ".问题是,当我重复与示例中相同的代码时,我收到错误“ [Vue warn]: Failed to resolve directive: scroll-to ”。 Here is my code:这是我的代码:

<div :class="{subelementos: isOpenAndroid}">
        <div class="subelementos2">
          <p v-scroll-to="'#prueba'" class="subelementos3" @click="menuClick('android')">Principios</p>

        </div>
</div>

And then in another component:然后在另一个组件中:

<div id="prueba">
      <p>TEXTEXT</p>
</div>

I don't know if someone is familiar with this tool.不知道有没有人熟悉这个工具。 I think i am missing something important.我想我错过了一些重要的东西。

PS: Maybe is a stupid question(sorry about that) but, do you think is mandatory to use Nuxtjs? PS:也许是一个愚蠢的问题(对此感到抱歉)但是,您认为使用 Nuxtjs 是强制性的吗? On the official page of the tool it is mentioned, but I think is optional https://vue-scrollto.netlify.app/docs/#nuxt-js .在该工具的官方页面上提到了它,但我认为是可选的https://vue-scrollto.netlify.app/docs/#nuxt-js

----EDIT---- - - 编辑 - -

The HTML, CSS and JS are in the same file, specifically on a .vue file. HTML、CSS 和 JS 在同一个文件中,特别是在 .vue 文件中。 I think that maybe I have to import an external library into my .vue file.我想也许我必须将一个外部库导入到我的 .vue 文件中。

The error indicates that you haven't registered the directive.该错误表明您尚未注册该指令。

The vue-scrollto docs describe how to setup the directive . vue-scrollto文档描述了如何设置指令 The plugin automatically registers the directive under the hood, and you can install the plugin in your app's entry point with Vue.use() :该插件会自动在后台注册指令,您可以使用Vue.use()在应用程序的入口点安装该插件:

// main.js
import Vue from 'vue'
import VueScrollTo from 'vue-scrollto'

Vue.use(VueScrollTo)

demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM