LWC
父子组件传参
组件名,参数名(遇大写,转为-小写)
-
父组件
aura
<div> 父组件 子组件: <c:leadDemoPIPL onXXX="{!c.closeModal}" onrefresh="{!c.refreshView}" recordId="{!v.recordId}"/> </div>
lwc
<c-lead-demo-p-i-p-i onXXX="{!c.closeModal}" onrefresh="{!c.refreshView}" recordId="{!v.recordId}"/>
-
子组件名
class 子组件{ @api recordId//与父组件内定义一致 //触发父组件方法 const event1 = new CustomEvent('父组件引用处调用方法 == xxx', { // detail contains only primitives // detail: {} }); this.dispatchEvent(event1); }
页面初始化
//获取Id 有时@api未成功拿到记录id
@wire(CurrentPageReference)
getStateParameters(currentPageReference) {
if (currentPageReference) {
const urlValue = currentPageReference.state.fragment;
if (urlValue) {
this.otherParams = urlValue;
let str = `${urlValue}`;
this.params = str.split('=');
this.recordId = str.split('=')[1];
this.IsParams = this.params[0] == 'id';
}
}
}
//页面初始化
connectedCallback() {
init({
recordId: this.recordId,
param: this.params[0],
}).then(result => {
result = JSON.parse(result);
console.log('result',result);
//compation 后台返回结果 - 改用前端直接提示
if (result != null) {
this.allData = result;
//页面相关数据初始化
}
}).catch(error => {
}).finally(() => {
});
}
页面跳转
import { NavigationMixin } from 'lightning/navigation';
...
class 组件名 extends NavigationMixin(LightningElement) {
navigateDonorDetails(){
this[NavigationMixin.Navigate]({
type:'standard__recordPage',
attributes:{
recordId:this.recordId,
objectApiName:'Account',
actionName:'view'
}
});
}
}
==========================================================
AURA
aura关闭自带弹窗
closeModal : function(cmp,event,helper){
$A.get('e.force:closeQuickAction').fire();
},
lwc触发
import { CloseActionScreenEvent } from 'lightning/actions';
this.dispatchEvent(new CloseActionScreenEvent());