Git Product home page Git Product logo

Comments (6)

surmon-china avatar surmon-china commented on July 22, 2024

@haoxl3

nuxt.js 中 layout 不仅仅是一个字符串,而是对应的 layouts 里的模板,你没有对应的模板,则必然找不到了。

  1. 如果使用 nuxt.js 的 layout 则需要模板,不必维护所谓的“变量”
  2. 若不使用,则可以在根组件自行根据“变量”来渲染元素

from surmon.me.

haoxl3 avatar haoxl3 commented on July 22, 2024

我有对应的模板,vertical及horizontal这两个模板都可以正确使用,如果我单个这样写layout : 'vertical'或者layout : 'horizontal'都是能渲染出来的。但现在需求是要通过页面的一个按钮来动态切换这两种布局,所以我的做法是通过切换layout的值来做到,但现在获取了值后赋给layout时总说这个值未定义,但我在computed里是能获取到的

from surmon.me.

surmon-china avatar surmon-china commented on July 22, 2024

你可以这样测试,测试一个猜想:在 layout 被读取并应用之前,computed 是还没有被实例化的。

layout : 'horizontal'

更换为

layout : (function() { console.log(this); return 'horizontal' }())

如若成立,则“将layout保存在 store ”这条路是行不通的。

from surmon.me.

haoxl3 avatar haoxl3 commented on July 22, 2024

我刚试过了,layout : (function() { console.log(this); return 'horizontal' }())这样写输出了undefined,页面是按horizontal渲染出来了。但是如果不把layout保存在store里面怎么做到其它所有页面都可以取到值?大神有其它思路来实现这个需求的么?

from surmon.me.

surmon-china avatar surmon-china commented on July 22, 2024

换个说法:“layout 不支持动态变更”。所以用自定义“layout”来实现吧,像我一样。

from surmon.me.

haoxl3 avatar haoxl3 commented on July 22, 2024

嗯,正在研究您的代码,非常感谢您的指点

from surmon.me.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.