草庐IT

Object方法

全部标签

javascript - 单击事件时从 jquery 触发 vue 方法

我正在尝试将点击事件附加到已存在的dom元素。...我似乎无法在我的jquery单击处理程序中访问外部vue方法。它将抛出logDataisnotdefined。newVue({el:'#events',mounted(){$('.logMe').on('click',function(){constdata=$(this).data('log-id');this.logData(data);//throwslogDataisnotdefined});},methods:{logData(id){console.log(id);//neverfires...hitserver},},}

javascript - 错误信息。 "Props with type Object/Array must use a factory function to return the default value."

我正在使用Vue-Cli3.0。我将此模块用于Vue.js。https://github.com/holiber/sl-vue-tree这是一个可自定义的可拖拽的Vue.js树组件,但我发现它无法复制对象的功能。https://github.com/holiber/sl-vue-tree/blob/master/src/sl-vue-tree.js#L715因为这里。JSON.parse(JSON.stringify(entity))所以我使用了这个模块并编辑了复制功能。https://www.npmjs.com/package/clonevarclone=require('clone

javascript - SettimeOut 间隔失败,出现 "Cannot convert undefined or null to object"

我正在使用tampermonkey编写用户脚本,但无法解决此错误,我们将不胜感激。我检测到按键很好,空格键会触发此功能,只要按键保持在向下位置,它就会重复自身。控制台正常写入输出大约30秒,然后出现TypeError。根据声誉限制,这是一个屏幕截图:用户脚本://==UserScript==//@nameTESTSTUFF--------------------//@namespacehttp://tampermonkey.net///@version0.1//@descriptiontrytotakeovertheworld!//@authorYou//@run-atdocument

JavaScript IE appendChild() - 意外调用方法或属性访问

我在IE中一直遇到这个问题。我有两个div,我用它们将选定的元素从一个拖到另一个。假设我在div1中有一个子元素(也是一个div),在div2中有一些子元素。我在div1的子元素上调用div2.appendChild()方法。它从div1中删除子项并将其附加到div2。如果我然后尝试将child追加回div1,我会在IE中收到以下异常“意外调用方法或属性访问”。它在Firefox中完美运行。请参阅下面的javascript代码片段。functionmoveSelectedGroupBoxItems(toLocation,grp){document.body.className='gro

javascript - 我正在尝试创建一个带有指针的 substr 方法……有更优雅的解决方案吗?

这是交易。我正在做一些字符串操作,我经常使用substr方法。但是,我需要使用它的方式更像是一种phpfread方法。然而,我的substr需要由指针引导。该过程需要像这样:varstring='Loremipsumdolorsitamet,consectetur'如果我读入,'Lorem'.....作为我的第一个substr调用:string.substr(offset,strLenth)//0,5然后我的下一个substr调用应该自动从我字符串中的这个位置开始的偏移量开始:offsetpointerstartsherenow=>ipsumdolorsitamet,consectet

javascript - 创建 javascript 对象的两种方法,我应该使用哪一种?

这些是创建javascript对象的方法:functionapple(optional_params){this.type="macintosh";this.color="red";this.getInfo=function(){returnthis.color+''+this.type+'apple';};}varapple={type:"macintosh",color:"red",getInfo:function(){returnthis.color+''+this.type+'apple';}}我真的更喜欢后者,因为它是Json语法,但我看到的第一个比后者多。它们在功能上有什么

javascript - 如何初始化 firstChild 这样我就不会得到 "x.firstChild is null or not an object"?

在我的JSP/HTML中我有这个:然后在我的javascript部分,我有一个像这样从onclick调用的函数;functionchangeLabel(){exampleLabel.firstChild.nodeValue='LABELHASCHANGED';}这在Chrome中工作正常,在Firefox和IE中什么都不做,页面上出现错误exampleLabel.firstChildisnullornotanobject.好吧,我可以认为没有firstChild,所以尝试做firstChild。任何事情都是NPE,我什至可以认为其他浏览器不会像Chrome那样自己初始化它。问题是,我该

javascript - jQuery 的位置方法问题

如果我有以下标记:我想获取child相对于其parent的位置,唯一的方法如下吗?:x=parseInt($('#child').css('left'));//returns0asneededy=parseInt($('#child').css('top'));//return0asneeded因为如果我执行以下操作:x=$('#child').position().left;//mostlikelywillnotreturn0y=$('#child').position().top;//mostlikelywillnotreturn0位置错误,因为偏移方法确实还添加了祖parent的

javascript - 在 Javascript 中堆叠方法

我有一个用这个片段创建的对象,它看起来像这样:...varsteps=newArray();this.createStep=function(){steps.push(newstep());returnsteps[steps.length-1];};this.getSteps=function(){returnsteps;};//returnsArraythis.removeStep=function(pos){steps.splice(parseInt(pos),1);};//integerpossitionzerobasethis.insertStep=function(pos){

javascript - 原型(prototype)和非原型(prototype)方法?

这个问题在这里已经有了答案:Useof'prototype'vs.'this'inJavaScript?(15个答案)关闭8年前。我想知道,JavaScript中的原型(prototype)方法和非原型(prototype)方法有什么区别?非常感谢任何帮助。