简体   繁体   English

我不知道如何组织使用基于组件的Web框架的Web应用程序

[英]I don't know how to organize a web app that uses component based web framework

I am trying to learn component based frameworks for frontend apps. 我正在尝试为前端应用程序学习基于组件的框架。 Currently, I am using RiotJS but it applies to any framework that uses the same concepts (React, Angular 2.0 etc). 目前,我使用的是RiotJS,但它适用于任何使用相同概念的框架(React,Angular 2.0等)。

In a basic MVC frontend frameworks (eg AngularJS), the controllers and router were very connected to each other. 在基本的MVC前端框架(例如AngularJS)中,控制器和路由器彼此非常连接。 But with a component based framework, the line between router and controllers is much wider. 但是使用基于组件的框架,路由器和控制器之间的界限要宽得多。 And this is what confuses me the most. 而这最让我困惑的是。

Here is one example of an app that I am trying to build: 以下是我要构建的应用程序的一个示例:

I have three main UI elements: Navigation Bar, Content Area, and Signin Form. 我有三个主要UI元素:导航栏,内容区域和登录表单。 So, I created three components: my-navbar, my-content, my-signin. 所以,我创建了三个组件:my-navbar,my-content,my-signin。 I was able to create multiple routes per component. 我能够为每个组件创建多个路由。 So for example, if there is a route changes, the navbar updates the active "module." 因此,例如,如果路线发生变化,导航栏将更新活动的“模块”。 Making this was easy because all I am doing is changing class of a list item. 这很简单,因为我所做的只是更改列表项的类。

Now, I want to load other tags inside <my-content></my-content> . 现在,我想在<my-content></my-content>加载其他标签。 In AngularJS, I was always changing the view completely (using ui-router). 在AngularJS中,我总是完全改变视图(使用ui-router)。 How can I achieve that in a component based framework. 如何在基于组件的框架中实现这一点。 Let's say that I have 2 more components called my-content-users-list-view, my-content-users-detail-view. 假设我还有两个名为my-content-users-list-view,my-content-users-detail-view的组件。 How can I add them to the component my-content based on the route? 如何根据路线将它们添加到组件my-content Do I just add it like document.innerHTML += '<my-content-users-list-view></my-content-users-list-view> ? 我只是添加它像document.innerHTML += '<my-content-users-list-view></my-content-users-list-view>

I know most of my syntax is RiotJS but I will understand it if you write it in another framework's syntax. 我知道我的大部分语法都是RiotJS,但是如果你用另一个框架的语法编写它我会理解它。

Thank you! 谢谢!

Essentially, yes, you could just append your tag as a DOM node and then call Riot to mount it: 基本上,是的,您可以将您的标记作为DOM节点附加,然后调用Riot来安装它:

riot.route('/awesome-route', () => {
    const tag = 'your-awesome-tag';
    const options = { ... };
    const elem = document.createElement(tag);
    // TODO empty your content container using pure DOM or jQuery to get rid of the previous route's view...
    document.querySelector('#content').appendChild(elem);
    riot.mount(elem, tag, options);
});

暂无
暂无

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

相关问题 不知道我的应用程序中如何安装AngularJS,我需要更新它 - Don't know how AngularJS is intalled in my app and I need update it 如何知道 web 应用程序可在浏览器或团队自定义应用程序上访问 - How to know that web app is access on browser or from teams custom app 对于AngularJS网络应用程序:使用后退按钮导航回网页时,网页不记得最后的滚动位置。为什么?怎么修? - For AngularJS web app: webpages don't remember their last scroll positions when navigating back to them with the back button. Why? How to fix? 在 Web 应用程序中进行文本编辑的良好框架(Angular/Rails Web 应用程序) - Good framework for text editing in web app (Angular/Rails web app) 我无法解决网络问题的代码中的angularjs错误无法正常工作 - angularjs error in the code that I can't solved the web don't works 如何在我的AngularJS网络应用程序中使用Spring Security保护基于角色的Web服务? - How to use Spring Security to secure Role based web services in my AngularJS web-app? 我想每页只显示 10 行。但我不知道如何? - I wana display just 10 rows per page.But i don't know how? 我不知道如何使用AngularJS在JSON文件中获取子数据 - I don't know how I can get the subdata in a JSON file with AngularJS 我正在使用角度翻译进行标签或字符串转换,我不知道如何翻译占位符文本 - I am using angular translate to label or string conversion, i don't know how to translate the placeholder text 如果不知道它是什么,如何在AngularJS中访问JSON属性名称? - How can I access a JSON property name in AngularJS if I don't know what it is?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM