message生命周期的问题
你代码是怎么写的? 不可能一直存在的,一般刷新后就没有了。
在MagentoThemeControllerResult里可以看到,有setCookie,也就是把messages存储到cookie里,便于js读取。
是不是改写 vendor/magento/module-theme/view/frontend/web/js/view/messages.js了?
应该是显示完成后,自动清除message的cookie
<code>/** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ /** * @api */ define([ 'jquery', 'uiComponent', 'Magento_Customer/js/customer-data', 'underscore', 'escaper', 'jquery/jquery-storageapi' ], function ($, Component, customerData, _, escaper) { 'use strict'; return Component.extend({ defaults: { cookieMessages: [], messages: [], allowedTags: ['div', 'span', 'b', 'strong', 'i', 'em', 'u', 'a'] }, /** * Extends Component object by storage observable messages. */ initialize: function () { this._super(); this.cookieMessages = _.unique($.cookieStorage.get('mage-messages'), 'text'); this.messages = customerData.get('messages').extend({ disposableCustomerData: 'messages' }); // Force to clean obsolete messages if (!_.isEmpty(this.messages().messages)) { customerData.set('messages', {}); } $.cookieStorage.set('mage-messages', ''); }, /** * Prepare the given message to be rendered as HTML * * @param {String} message * @return {String} */ prepareMessageForHtml: function (message) { return escaper.escapeHtml(message, this.allowedTags); } }); }); </code>
maidoubaba 发表新评论
Windows 下会有显示完不清楚的现象。