草庐IT

修改组件properties

全部标签

javascript - 将 html 传递给 Vue 组件

目前我将一些参数传递给vue组件hello','goodbye']"slider是“html”slider或带有图像的slider。虽然我传入的html会变得更复杂,可能有30行,但作为参数将更难阅读和管理,这工作正常。我可以传入外部引用并将其拉入组件吗?{{content}}如您所见,组件中的循环是一个非常简单的v-for。 最佳答案 不要使用属性传递HTML,而是使用Slots:Supposewehaveacomponentcalledmy-componentwiththefollowingtemplate:I'mthechil

javascript - 如何将 Prop 传递给组件的故事?

我想为vue-select添加一些故事组件使用Storybook,但我正在努力处理更复杂的案例,其中涉及传递Prop或方法。当我在模板内传递Prop时它起作用:storiesOf('VSelect',module).add('withlabeledcustomoptions',()=>({components:{VSelect},template:``}))我发现它的可读性不是很好,所以我想将它们分别作为props或data传递:.add('withlabeledcustomoptionsasprops',()=>({components:{VSelect},props:{option

javascript - 未捕获的类型错误 : Cannot read property 'document' of undefined

我有以下功能,在我测试过的几台PC上运行良好。我已经在Chrome、IE和Firefox上测试过,没有任何问题。但是,有一台特定的PC(运行Chrome)在该行抛出此错误“UncaughtTypeError:Cannotreadproperty'document'ofundefined”:win.document.write(data);难道是因为win为null?如果是这样,为什么这台特定PC会出现这种情况?是否有一些Chrome设置需要设置?方法:functionviewReport(){console.info('generatingeventreport');varfrmDat

javascript - react : TypeError: Cannot read property 'propTypes' of undefined

请我为以下reactjs页面编写一个单元测试。exportdefaultclassCollapsibleextendsReact.Component{staticpropTypes={title:React.PropTypes.string,children:React.PropTypes.any,};render(){const{title}=this.props;return({title}{this.props.children});}}跟着啧啧Here我在下面写了我的测试describe('Collapsible',()=>{it('works',()=>{letrendere

javascript - 当 redux 状态更新时在组件上调用 forceUpdate()

我有一个问题,redux状态被成功更新,但react组件没有重新渲染,经过一些研究我相信[forceUpdate()][1]可以解决我的问题,但我是不确定实现它的正确方法,即在redux状态更新之后。我尝试在github上查找示例,但没有成功。 最佳答案 正如其他人所说,forceUpdate()基本上是一种hack。只要Prop和状态发生变化,您就可以免费获得更新。React和Redux可以无缝协作,因此请避免任何此类黑客行为。如果您的Redux状态正确更新而您的ReactView没有正确更新,那么您很可能没有以不可变的方式更新。

javascript - Vue (nuxt) 中的全局组件

在构建Vue应用程序时,我们在每个模板中重复使用某些Vue组件。我们的网格系统存在于.region、.layout、.grid、.column元素之外。它们都是独立的Vue组件(,...)。我们现在在每个模板中都这样做:importBlMainfrom'~components/frame/main/Main.vue'importBlRegionfrom'~components/frame/region/Region.vue'importBlLayoutfrom'~components/frame/layout/Layout.vue'importBlGridfrom'~component

javascript - 使用 TypeScript 强制 React 组件命名

有React+TypeScript的应用,所有的组件类都要大写,有Component后缀,例如:exportclassFooBarComponentextendsReact.Component{...}应用程序被弹出create-react-application应用程序,即使用Webpack构建。如何强制组件命名与样式指南保持一致,至少对于组件类而言,当存在不一致时会在构建时抛出错误?我相信这不能单独使用TSLint/ESLint来实现。如果应该对TypeScript和JavaScript使用不同的方法,那么针对这两种语言的解决方案会很有帮助。 最佳答案

javascript - Angular 2 使用组件属性动态设置 routerLink

我创建了一个组件,其中包含一个具有routerLink属性的元素,我想从使用该组件的模板中设置该属性。当我尝试执行此操作时,我收到错误消息“无法读取未定义的属性‘路径’”。我的组件看起来链接了这个:信息框.component.tsimport{Input,Component}from"@angular/core";import{ROUTER_DIRECTIVES}from"@angular/router";@Component({selector:"info-box",template:require("./info-box.component.html"),directives:[R

javascript - [Vue 警告] : Error in render function: "TypeError: Cannot read property ' first_name' of null"

我有以下Navigation.vue组件:{{user.first_name}}import{mapActions,mapGetters}from'vuex'exportdefault{name:'hello',methods:{...mapActions(['myAccount'])},mounted:function(){if(localStorage.getItem('access_token')){this.myAccount()}},computed:{...mapGetters(['user'])}}此代码返回:[Vuewarn]:Errorinrenderfunction

javascript - 未捕获的类型错误 : Cannot read property 'offsetWidth' of null

这个问题在这里已经有了答案:GoogleMAPAPIUncaughtTypeError:Cannotreadproperty'offsetWidth'ofnull(26个答案)OffsetWidthnullorundefined(Can'tfindsolution)[closed](1个回答)关闭8年前。不幸的是,我在发布这个问题之前阅读了几个线程,我找不到适合我的问题的答案。这是我的代码片段-->functionpopulateIframe(id){varifrm=document.getElementById(id);ifrm.src="business_data_to_excel