Таким образом, правильный способ справиться с этим - использовать компонент aura:html
. Для этого есть несколько параметров:
- aura: id- String - ваш идентификатор, чтобы найти элементы внутри JS
- tag- String- the html тег
- HTMLAttributes- Map - нет необходимости явно устанавливать это на .cmp, мы будем использовать Js
<!--YourComponent.cmp-->
<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable" access="global" >
<!--Remember to define your binding attribute-->
<aura:attribute name="image" type="String"/>
<lightning:card title="Partner Information">
<div class="slds-p-around_medium">
<p>
<!--Set you attribute as the value of the lightning:input component-->
<lightning:input aura:name="image"
label ="Enter image url"
value="{!v.image}"
type="text"
onchange="{!c.handleUrlChange}"/>
</p>
<br/>
<!--Set the aura:id so you can access it in js, use component.find to locate-->
<aura:html aura:id="imgDiv" tag="img"/>
</div>
</lightning:card>
</aura:component>
//YourComponentController.js
({
handleUrlChange : function(component, event, helper) {
//Grab the value from the attribute or you can use event.getParam("value");
var imageUrl = component.get("v.image");
//Define the map, find the img tag generated by aura:html,
//and set the HTMLAttributes to your map
var newMapAttributes = {"src": imageUrl};
component.find("imgDiv").set("v.HTMLAttributes",newMapAttributes);
}
})
Вы также используете url
атрибут вашего тега изображения вместо src
атрибута. Возможно, вы сможете напрямую связать элемент img
, но aura:html
работает очень хорошо. Надеюсь, что ответ на ваш вопрос!