简体   繁体   English

Nuxt.js 服务器端 Javascript 问题,框架混乱

[英]Nuxt.js server side Javascript issue, framework confusion

A partner and I are working on website for a school project, and we have decided to use Vue.js and Nuxt.js as the front-end frameworks, and Vuesax as a UI Framework.我和一个合作伙伴正在为一个学校项目做网站,我们决定使用 Vue.js 和 Nuxt.js 作为前端框架,使用 Vuesax 作为 UI 框架。 Neither of us have any experience with these frameworks or frankly web development until recently.直到最近,我们都没有任何使用这些框架或坦率地说 Web 开发的经验。 We ran into our first major issue when we were trying to create a profile drop down menu, where the items of the menu become visible when you click the profile avatar, however when trying to use the event listener, we realized Nuxt.js (based on node) was meant for universal javascript rather then strictly client side, so when we use "document.getElementId" for event handling, it says that it is not defined.当我们尝试创建配置文件下拉菜单时,我们遇到了第一个主要问题,当您单击配置文件头像时,菜单项会变得可见,但是在尝试使用事件侦听器时,我们实现了 Nuxt.js(基于在节点上)是用于通用 javascript 而不是严格的客户端,所以当我们使用“document.getElementId”进行事件处理时,它说它没有定义。 (no DOM) (没有 DOM)

错误信息 We really don't know what to do from here - find a new framework or plug-in/extension - and we are wondering if we could get some insight.我们真的不知道从这里开始做什么——找到一个新的框架或插件/扩展——我们想知道我们是否能得到一些见解。 We want to be able to use Javascript purely to handle frontend events.我们希望能够纯粹使用 Javascript 来处理前端事件。 Moving forward, we also want to fetch information from a database (currently in MySQL but may change due to feedback), and we were thinking of using Spring Boot as our backend framework, as it allows us to handle requests, create servlets in Java(our most comfortable language)and also has Tomcat.展望未来,我们还想从数据库中获取信息(目前在 MySQL 中,但可能会因反馈而改变),我们曾考虑使用 Spring Boot 作为我们的后端框架,因为它允许我们处理请求,在 Java 中创建 servlet(我们最舒适的语言)并且还有 Tomcat。

We have done a lot of research and consulted a lot of websites and acquaintances, but sometimes it is difficult to find things that pertain to something so specific, in this case our project.我们做了很多研究,咨询了很多网站和熟人,但有时很难找到与如此具体的东西相关的东西,在这种情况下,我们的项目。 We are also having trouble finding a system of frameworks that is cohesive and compatible with each other.我们也很难找到一个具有凝聚力和相互兼容的框架系统。 We are more than willing to learn, so any insight, feedback or suggestions are appreciated!我们非常愿意学习,所以任何见解、反馈或建议都值得赞赏!

From the image, you are trying to perform dom manipulation in nuxt and both windows and document are not defined.从图像中可以看出,您正在尝试在 nuxt 中执行 dom 操作,但未定义 windows 和 document。

To do what you're trying to do you have to try it like this.要做你想做的事,你必须像这样尝试。

<template>
  // @click is the event listener to change the state
  <button @click="mobileNavOpen = !mobileNavOpen">Toggle btn</button>
  // bind the show class conditonally according to mobileNaveOpen state and add the display state to the show class.
  <div :class="{show : mobileNavOpen}">
    <ul class="navbar-nav align-items-center">
      <li class="nav-item active">
        <nuxt-link class="nav-link" to="/">
          Home
        </nuxt-link>
      </li>
      <li class="nav-item">
        <nuxt-link class="nav-link" to="/about">
          About
       </nuxt-link>
      </li>
    </ul>
  </div>
</template>
<script>
 export default {
    data() {
      return {
        mobileNavOpen: false,
      }
    },
    methods: {
      closeMobileNavbar() {
        this.mobileNavOpen = false
      }
    }
  }
</script>

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

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