2

mage/cookies is JS component which initialized on the element with the selector specified as element selector. Syntax : <script type="text/x-magento-init"> { // components initialized on the element defined by selector "<element_selector>": { "<js_component1>": ..., "<js_component2>": ... }, // ...


2

mage/url widget is not used to fetch backend base URL in Magento 2. You need to create a template file using layout XML and define the base URL of backend under the template file. You can define any Global variable and set your URL in it. Create a simple layout XML file to fetch backend URL of the site using JS, Create default.xml file for global ...


1

In phtml file add this code: <input type="hidden" id="testUrl" value="<?php echo $this->getUrl(); ?>"/> By using Id we can get base url in JS file $("#testUrl").val(); Hope it will help


1

<script type="text/javascript"> define(['Magento_Customer/js/model/customer'], function (customer) { if (customer.isLoggedIn()) { // Do your Logic. } }); </script>


1

That is happening because you have href="#", your options are to remove href="#" (valid HTML5) or add the below javascript inside your click event: e.preventDefault();


1

In magento you should avoid inject direct script in templates like <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script> Not like that The correct way below You can add path vue js to file requirejs-config.js var config = { paths: { vue: 'https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue', } }; /*No js ...


1

I'd recommend using the script method rather than the text method, it's easier for other developers to understand, it's less code, and meets Magento's official instructions. To do this use the same script or link XML as normal but include src_type="url". Check this out official Doc URL. <?xml version="1.0" ?><page xmlns:xsi="http://www.w3.org/2001/...


Only top voted, non community-wiki answers of a minimum length are eligible