vue.js 2在vue-material中路由(vue.js 2 routing in vue-material)
我目前正在开发一个将vue.js与vue-material一起使用的网页。 我做了类似这样的菜单。
我的目标是,其中一个菜单项将用户重定向到另一个页面。 我试着作为官方文件说:
<md-list-item @click="$refs.sidebar.toggle(); this.$router.push('/company');"> <md-icon>start</md-icon> <span>Starred</span> </md-list-item>
但我收到了一条警告:
[Vue warn]: Error in event handler for "click": "TypeError: this.$router is undefined"
我尝试了所有版本:
$router.push('/company');
,router.push('/company');
,this.router.push('/company');
但是stil不起作用。另一方面,我试图用
router-link
标签包围md-list-item
,但它也没有用。如何定义内联路由(在
@click
部分)?Thx提前回复!
更新:
我在
app.js
vue-route
配置:import VueRouter from 'vue-router' Vue.use(VueRouter) ... const routes = []; const router = new VueRouter({ routes }) const app = new Vue({ el: '#app', beforeUpdate: function() { console.debug('app rerendering'); console.debug(this); }, beforeCreate: function() { console.debug('app creating'); console.debug(this); }, router, });
但问题是一样的...如果我试着打电话给这个。
$router.push('/company')
我得到了同样的错误:TypeError: this.$router is undefined
I'm currently working on a web page what uses vue.js with vue-material. I made a similar menu like this.
My goal, that one of the menu item redirect the user to an another page. I tried as a official doc says:
<md-list-item @click="$refs.sidebar.toggle(); this.$router.push('/company');"> <md-icon>start</md-icon> <span>Starred</span> </md-list-item>
But I got a vue-warn message:
[Vue warn]: Error in event handler for "click": "TypeError: this.$router is undefined"
I tried the all version:
$router.push('/company');
,router.push('/company');
,this.router.push('/company');
but stil does not works.On the other hand i tried to surround the
md-list-item
withrouter-link
tag but it didnt work as well.How can I define the routing inline (in the
@click
section)?Thx for the responses in advance!
UPDATE:
My
vue-route
config inapp.js
:import VueRouter from 'vue-router' Vue.use(VueRouter) ... const routes = []; const router = new VueRouter({ routes }) const app = new Vue({ el: '#app', beforeUpdate: function() { console.debug('app rerendering'); console.debug(this); }, beforeCreate: function() { console.debug('app creating'); console.debug(this); }, router, });
But the problem is the same... If I try to call this.
$router.push('/company')
I got a same error:TypeError: this.$router is undefined
原文:https://stackoverflow.com/questions/45945593
最满意答案
使用其他问题中描述的
Mapper
可以让您走上正确的道路。 正如doc [0]中提到的,你会得到一堆sqlalchemy.orm.relationships.RelationshipProperty
,然后你就可以在与每个RelationshipProperty
关联的mapper
上使用class_
来进入类:from sqlalchemy.inspection import inspect rels = inspect(Thing).relationships clss = [rel.mapper.class_ for rel in rels]
Using the
Mapper
as described in that other question gets you on the right path. As mentioned on the doc [0], you will get a bunch ofsqlalchemy.orm.relationships.RelationshipProperty
, and then you can useclass_
on themapper
associated with eachRelationshipProperty
to get to the class:from sqlalchemy.inspection import inspect rels = inspect(Thing).relationships clss = [rel.mapper.class_ for rel in rels]
相关问答
更多-
SQL:我必须完全不同意S.Lott的回答 。 我并不了解开箱即用的解决方案,但可以发现所有对给定表具有ForeignKey约束的表。 需要正确使用INFORMATION_SCHEMA视图,例如KEY_COLUMN_USAGE , TABLE_CONSTRAINTS , TABLE_CONSTRAINTS等。请参阅SQL Server示例 。 有了一些限制和扩展,新版关系数据库的大多数版本都支持INFORMATION_SCHEMA标准。 如果在表中包含所有FK信息和对象(行),则只需运行少量SELECT语句 ...
-
我不会将这种关系用于目的,因为从技术上讲,它不是你正在建立的关系(所以保持双方同步的所有技巧都不行)。 国际海事组织,最清洁的方式将是定义一个简单的查询,它会返回你正在寻找的对象: class Account(Base): ... # please note added *backref*, which is needed to build the #query in Account.get_other_collections(...) collections = rela ...
-
这些问题的经典答案是创建一个SQL VIEW。 视图类似于动态虚拟表 - 在查询中使用视图名称而不是表名,DBMS运行视图定义的查询以在视图上生成查询的行。 因此,您在访问视图时,而不是在创建视图时,根据表中的数据查看行。 您可以使用诸如的语句创建此视图 CREATE VIEW PROT_WITH_UNITS AS SELECT * FROM dna_extraction_protocols P JOIN measurement_units M ON P. ...
-
1)这两个查询之间有什么区别? 他们几乎做同样的事情。 前者是查询SQLAlchemy提供的对象的方法( Flask用于访问数据库的库)。 后者是查询Flask-SQLAlchemy库添加的模型的便捷方式。 它使您的查询更具可读性+使用一些有用的方法扩展查询。 看一下flask_sqlalchemy.BaseQuery类的来源,看看它们: get_or_404() , first_or_404()和paginate() 。 通常您希望使用后一种方法来查询对象。 2)我正在尝试获取具有特定年龄的学生列表,但以 ...
-
你可以从locate_all_froms获得所有表格,就像这样 from sqlalchemy import Table from sqlalchemy.sql.selectable import Alias tables = set() for f in query.statement.locate_all_froms(): if isinstance(f, Table): tables.add(f) elif isinstance(f, Alias): ...
-
除了您发布的代码中的一些拼写错误(请参阅zzzeek的评论),看起来问题将通过替换代码来解决: jack.save_datas.stations = [Station('name1','123456',None,None,None)] 以下一个: jack.save_datas[0].stations = [Station('name1','123456',None,None,None)] 原因如下:在您的情况下,您为一个类成员分配/创建一个stations属性。 不仅这不能做正确的工作,它可能会损害您 ...
-
当两个不同实体之间存在Many to Many关系时,主要使用db.Table 。 这里父母和孩子都是User 。 在你的情况下,下面的代码会很好: class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True, unique=True, nullable=False) email = db.Column(db.String(120), unique=True ...
-
使用其他问题中描述的Mapper可以让您走上正确的道路。 正如doc [0]中提到的,你会得到一堆sqlalchemy.orm.relationships.RelationshipProperty ,然后你就可以在与每个RelationshipProperty关联的mapper上使用class_来进入类: from sqlalchemy.inspection import inspect rels = inspect(Thing).relationships clss = [rel.mapper.class ...
-
事实证明, text是PostgreSQL中的保留字。 我重命名了列名并重构了我的代码以匹配。 这解决了这个问题。 It turns out that text is a reserved word in PostgreSQL. I renamed the column name and refactored my code to match. This solved the issue.
-
更新:我认为我认为我试图构建课程的方式并不是让SQLAlchemy的幕后魔术工作正确。 因此,在使用类继承之后,这个完整的代码工作得很好: from time import time from sqlalchemy import Column, String, Integer from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import create_engine from sqlalchemy.orm impo ...