草庐IT

vuejs-ssr-typescript

全部标签

javascript - TypeScript 中的“This”作用域

在我的网页上,我删除了表格中行上的图标,如下所示:我正在使用TypeScript,其中我附加了一个onClick监听器来执行一个名为OnRemoveClick的函数,就像这样$('.remove').click(this.OnRemoveClick);OnRemoveClick将2个字段置零(在行上单击删除图标),然后执行2个函数,如下所示:privateOnRemoveClick():void{$(this).parents('tr').find('.input-qty').val('0');$(this).parents('tr').find('.sub-total').html(

javascript - TypeScript 中的多类继承

有什么方法可以解决最多只能扩展一个其他类的问题。classBar{doBarThings(){//...}}classBazz{doBazzThings(){//...}}classFooextendsBar,Bazz{doBarThings(){super.doBarThings();//...}}这个目前是做不到的,TypeScript会报错。人们可以通过使用接口(interface)在其他语言中解决这个问题,但在TypeScript中不可能解决这些问题。欢迎提出建议! 最佳答案 这可以通过接口(interface)实现:int

javascript - 为什么 typescript 不提示某些 undefined variable

我有以下示例:classUncle{constructor(publicname:string){}talk(){return"Hellomynameis"+name;}}letp:Uncle=newUncle("Jo");console.log(p.talk());对于某些变量名,typescript(目前版本2.1.4)不会提示它们没有在您的程序中定义(在方法讨论中,名称是在没有这个的情况下使用。)。name就是其中之一。如果我将变量重命名为firstName,编译器会正确地提示...errorTS2663:Cannotfindname'firstName'.Didyoumeant

javascript - Vuex + VueJS : Passing computed property to child is undefined

我正在阅读这个documentationonVuecomponents,但使用Vuex数据作为我的组件属性。在这个例子中,如果country_id在data方法中,它工作正常。但是当country_id是一个从Vuexstore返回数据的计算属性时,子组件的internalValue总是被初始化为undefined。我做错了什么?父组件:exportdefault{computed:{country_id(){returnthis.$store.state.user.country_id}},mounted:function(){this.$store.dispatch('user/l

javascript - 有没有办法在VueJS中使用mixin继承模板

有人知道如何继承mixin及其模板吗?或者如何从mixin中注入(inject)动态元素或组件?编辑:我不想修改问候语组件,我有两个Mixins:添加方法raise404()并显示100%层的404Mixin和具有在Angular落显示微调器的loading()方法的LoaderMixin。我可以继承他们的方法,但我必须在我想使用它的每个组件中复制html。谢谢mixin={template:'{{foo}}',data(){return{foo:'Hello',};},}//ThisshouldbeHelloWorld!Vue.component('greeting',{mixins

javascript - npm run dev 命令不适用于 vuejs 的 hackernews 示例

我正在尝试从vuejs的githubrepository运行vue-hackernews-2.0示例在设置部分,它解释了如何安装项目:#installdependenciesnpminstall#oryarn#serveindevmode,withhotreloadatlocalhost:8080npmrundev#buildforproductionnpmrunbuild#serveinproductionmodenpmstart我安装了npm。在server.js中将端口更改为8888后,我在命令行中键入“npmrundev”。>vue-hackernews-2.0@devD:\U

javascript - 我可以在 TypeScript 中将函数限制为纯函数吗?

有没有办法让一个函数成为pure仅在TypeScript中(因此不接受非纯函数)?如果是,是哪个? 最佳答案 您也许可以编写一些TSLint规则来捕捉大多数常见情况(例如,访问外部变量),但检查类似的东西几乎是不可能的,因此没有办法真正知道100%。您(和您的团队)仍然需要遵守纪律。 关于javascript-我可以在TypeScript中将函数限制为纯函数吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow

javascript - 在 Typescript 中扩展基类属性

我正在尝试为ReactReduxForm的Control组件创建一个包装类以添加额外的功能。这是基类/组件定义:exportclassControlextendsReact.Component,{}>{staticcustom:React.ComponentClass>;staticinput:React.ComponentClass>;statictext:React.ComponentClass>;statictextarea:React.ComponentClass>;staticradio:React.ComponentClass>;staticcheckbox:React.C

javascript - Typescript 使用 Rx.js 过滤器运算符区分联合类型?

typescript支持discriminatedunions.如何将与Rxjs相同的概念扩展到filter下面例子中的运算符?interfaceSquare{kind:'square';width:number;}interfaceCircle{kind:'circle';radius:number;}interfaceCenter{kind:'center';}typeShape=Square|Circle|Center;constobs$:Observable=of({kind:'square',width:10});//Expectedtype:Observable//Actu

javascript - VueJS 组件发出重复事件

当我的鼠标光标进入和离开我的VueJS组件时,分别调用以下方法。当光标进入和离开我的组件时调用的方法://locatedin"methods"sectionofmyVuecomponentfileonMouseEnter(){window.Event.$emit("mouse-entered",this.index);console.log("Mouseentered");},onMouseLeave(){window.Event.$emit("mouse-left",this.index);console.log("Mouseleft");},这就是我的控制台在我的光标进入和离开组件