草庐IT

历时两天半由浅入深总结了20道Vue高频面试题

全部标签

javascript - Vue 中的嵌套循环

我有一个通过vue传递的对象的对象,我这样做是为了运行:@{{question}}但是我收到这个错误:属性或方法“subjects”未在实例上定义,但在渲染期间被引用。确保在数据选项中声明响应式数据属性。(在根实例中找到)如何在vue中运行嵌套循环? 最佳答案 举个例子:varvm=newVue({el:'#app',data:{questions:[{subjects:['question1.1','question1.2']},{subjects:['question2.1','question2.2']}]}}){{subje

javascript - Vue.js 'v-bind:class' 不更新,即使模型更新

我有一个项目列表,我想对当前选定的项目应用一种样式。我也在使用Vuex来管理状态。我的列表组件:constList=Vue.component('list',{template:'0">'+''+'{{g.text}}'+''+''computed:{items:function(){returnthis.$store.state.items;}},methods:{selectItem:function(index){this.$store.commit('selectItem',index);}}});我的商店:conststore=newVuex.Store({state:{it

javascript - 使用 Vue.js 播放声音

如何使用Vue.js播放声音?似乎我不能只做常规的方式。importVuefrom'vue'importAppViewfrom'./components/App.vue'console.log('Playoutsideofvue')varaudio=newAudio('file.mp3')audio.play()newVue({el:'#root',mounted(){console.log('Willitplayhere??lol')varaudio=newAudio('file.mp3')audio.play()},render:h=>h(AppView)})正如它所说,音频未定义

javascript - 在 vue 路由中匹配查询参数

有什么方法可以通过查询参数进行路由吗?我想匹配以下路由:site.com/?foo=123。我试过类似的东西{path:'/\?foo=[\d]*'}没有成功。 最佳答案 不幸的是,您无法匹配路由定义的path字符串中的查询参数。VueRouter使用path-to-regexp和itsdocumentation说:TheRegExpreturnedbypath-to-regexpisintendedforusewithpathnamesorhostnames.Itcannothandlethequerystringsorfragm

javascript - 如何将弹出框内的输入标签绑定(bind)到 Vue 模型

我在弹出内容中有一个input,如下所示:JSFiddleHTML:'>ClickMe!{{message}}这是JS:newVue({el:'#vue-app',data:{message:'IamaText'}});$(document).ready(function(){$('[data-toggle="popover"]').popover();});如您所见,data-content的输入绑定(bind)得很好,但里面的输入没有绑定(bind)!任何想法将不胜感激。 最佳答案 你可以这样使用:这是工作演示:https://

javascript - 如何从父组件将类应用到 Vue.js 功能组件?

假设我有一个功能组件:Somefunctionalcomponent现在我在一些带有类的父级中渲染这个组件:结果DOM没有将new-class应用于Functional子组件。现在据我了解,Vue-loader将Functional组件针对render函数context编译为explainedhere.这意味着类不会被直接应用和智能合并。问题是-如何在使用模板时让函数式组件与外部应用的类很好地配合?注意:我知道可以通过渲染函数轻松实现:Vue.component("functional-comp",{functional:true,render(h,context){returnh("

javascript - 在 VUE 中切换样式时边框样式无法正确呈现

检查这个demo下面:newVue({ el:'#app',data:{ flag:true},computed:{ style(){letstyleA={borderBottom:'1pxsolidred',borderRight:'1pxsolidred'};letstyleB={ border:'1pxsolidgreen',borderRight:'1pxsolidred'}returnthis.flag?styleA:styleB}},methods:{ changeStyle(){ this.flag=!this.flag;}}}).box{width:100px;heig

javascript - 如何使用谷歌浏览器调试 Vue 应用程序

我想摆脱一直使用console.log并更频繁地使用Chrome开发者调试工具。我觉得这很好Howtostopusingconsole.log()andstartusingyourbrowser’sdebugger关于一般调试(设置断点、逐行执行等)但是当我尝试在现实生活中使用它时——这意味着在我正在处理的vue(nuxt)应用程序中使用它——我无法让它工作。我的所有文件都组合成更复杂的javascript文件,我无法对其进行调试。然后我找到了这个帖子:Debugging.vuecomponentinChrome我认为这会阐明这件事,但不幸的是我不知道该怎么做。我添加了这个:confi

javascript - Vue.js 访问父组件

我有一个具有此方法的子组件:getSubscriptions(){MessageService.subscriptions()this.$parent.loading=true;.then((data)=>{if(data.data.subscriptions==null){this.noSubscriptions=true;}else{this.subscriptions=data.data.subscriptions;}this.$parent.loading=false;}).bind(this);}所以我想在我的父组件中显示一个加载圆,我这样访问它:this.$parent.l

javascript - Vue - 单击按钮提交表单

我有一个用户可以上传图片的组件,我还想添加一个删除图片的功能。我添加了一个删除当前图像的按钮,但问题是表单也被提交了,我想避免这种情况。我只需要删除当前图像(如果存在)。这是脚本:+Removeimageexportdefault{props:['imageSrc'],methods:{previewThumbnail:function(event){varinput=event.target;if(input.files&&input.files[0]){varreader=newFileReader();varvm=this;reader.onload=function(e){vm