我有以下代码来查看用户是否已登录.它有效,因为它在客户区域内工作(用户已登录),但即使客户仍在登录,也无法在客户区域外工作.
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) { ?>
<li class="link wishlist" data-bind="scope: 'wishlist'">
<a <?php /* @escapeNotVerified */ echo $block->getLinkAttributes() ?>><?php echo $block->escapeHtml($block->getLabel()) ?>
<!-- ko if: wishlist().counter -->
<span data-bind="text: wishlist().counter" class="counter qty"></span>
<!-- /ko -->
</a>
</li>
<li>Hello World</li>
?>
<?php
}
else {
?>
<li>Not logged in</li>
<?php
}
?>
<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"wishlist": {
"component": "Magento_Wishlist/js/view/wishlist"
}
}
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud) 我有一个呈现复选框的 React 组件。问题是需要单击两次才能变为选中状态,然后单击两次才能变为未选中状态。
JS:
import React, { Component } from "react";
class CheckboxRow extends Component {
constructor(props) {
super(props);
this.state = { checked: false };
}
inputChangedHandler() {
this.setState({ checked: !this.state.checked });
}
render() {
return (
<div className="checkbox-row">
<input
id={this.props.id}
type="checkbox"
onChange={() => this.inputChangedHandler()}
checked={this.state.checked}
/>
<label htmlFor={this.props.id} className="checkbox-row__label">
Label goes here
</label>
</div>
);
}
}
export default CheckboxRow;
Run Code Online (Sandbox Code Playgroud)
那么我需要做什么才能使复选框一键变为选中状态,一键变为未选中状态?