首页 \ 问答 \ vue.js 2在vue-material中路由(vue.js 2 routing in vue-material)

vue.js 2在vue-material中路由(vue.js 2 routing in vue-material)

我目前正在开发一个将vue.jsvue-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 with router-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 in app.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
更新时间:2023-01-24 14:01

最满意答案

使用其他问题中描述的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 of sqlalchemy.orm.relationships.RelationshipProperty, and then you can use class_ on the mapper associated with each RelationshipProperty 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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)