Use Lodash to filter whether the object value is undefind or null Author: Chuwen Time: 2023-03-31 Classification: JavaScript comment ##Function realization We use Lodash's [omitBy]( https://www.lodashjs.com/docs/lodash.omitBy "OmitBy") method parameter 1. 'object' (Object): source object. 2. '[predict=_. identity]' (Function): Call the function of each attribute. (* That is, when this condition is met, it will be filtered out *) ```ts const { omitBy } = require("lodash") const filterParams = { day: 1, min: undefined, max: null, age: "" } omitBy(filterParams, (value, key) => value === undefined || value === null) //Running result: {day: 1, age: ''} ```
Shopify Partner uses JS to create a store Author: Chuwen Time: 2022-12-28 Classification: JavaScript comment #Shopify Partner uses JS to create a store Eliminate tedious operation steps ###Step 1 Open https://partners.shopify.com/organizations >If you have not logged in, you need to log in first ###Step 2 Open the browser * * developer tool * *. Take Chrome for example, press F12 to open it ###Step 3 >Please pay attention to modifying the 'subdomain' and 'storeName' values of the code Find the 'Console' Tab in * * Developer Tools * *, paste the following code, and press the 'Enter' key to run ###Step 4 Wait about 20 seconds, because it takes a long time to create a store. After the store is successfully created, it will automatically open your newly created store ```js var organizationID = window. RailsData.user.organizationID var subdomain = 'test-008' var storeName = subdomain.replaceAll("-", " ").toUpperCase() fetch(` https://partners.shopify.com/ ${organizationID}/api/graphql`, { headers: { 'content-type': 'application/json', 'x-csrf-token': document.querySelector(`meta[name="csrf-token"]`).content }, body: JSON.stringify({ operationName: "ShopCreate", variables: { input: { storeType: "PARTNER_TEST_STORE", developerPreviewHandle: "checkout_extensibility", storeName, address: { CountryCode:'US'//Country }, subdomain, signupSourceDetails: 'test_app_or_theme' } }, query: "mutation ShopCreate($input: ShopCreateInput!) {\n shopCreate(input: $input) {\n redirectUrl\n userErrors {\n field\n message\n __typename\n }\n __typename\n }\n}\n" }), method: 'POST', mode: 'cors', credentials: 'include' }) .then((response) => response.json()) .then((data) => { Console. log ('Store created successfully! ', data); window.open(data.shopifyCreate.redirectUrl, "_blank") }) .catch((error) => { Console. error ('Failed to create the store! ', error); Alert (` Failed to create the store! ${error} `) }); ``` --- Gist: https://gist.github.com/PrintNow/067f1d494a2f723e1486d9527997942ca
Laravel mix+TailwindCSS Run npm run watch Infinitely recompile CSS Author: Chuwen Time: 2022-05-21 Classification: JavaScript comment First, the answer is: https://github.com/laravel-mix/laravel-mix/issues/1942 ##Preamble Recently, I am planning a new theme design for this blog. I want to use modern front-end technology and have some experience in using Laravel mix, so I chose Laravel mix as the scaffold ##Question `Webpack. mix. js ` Configuration: ```js const mix = require('laravel-mix'); require('mix-tailwindcss'); mix.disableSuccessNotifications() .ts('src/app.ts', 'theme/assets') .setPublicPath('theme/assets') .sass("src/assets/sass/app.scss", "theme/assets") .tailwind('./tailwind.config.js') .webpackConfig({ module: { rules: [ { test: /\.tsx?$/, loader: "ts-loader", exclude: /node_modules/ } ] } }) mix.browserSync({ proxy: '127.0.0.1:3792', files: ["theme/**/*.php", "src/*.js", "src/*.css"], open: false }) ``` `Tailwind. config. js ` Configuration: ```js module.exports = { content: require('fast-glob').sync([ './ src/**/*. {html,js,ts}', './ node_modules/tw-elements/dist/js/**/*.js', './ theme/**/*.php' ]), theme: { extend: {}, }, plugins: [ require('tw-elements/dist/plugin') ], } ``` Use the above configuration, and then run 'npm run watch'. The terminal flashes the compilation results all the time, and then the computer fan roars: ! []( https://cdn.nowtime.cc/2022/05/21/912061657.png ) ##Solution Fortunately, I searched in Google+English (in poor English?) and found this * * issues * *: https://github.com/laravel-mix/laravel-mix/issues/1942 Flip around and find that the solution given by this person is feasible: https://github.com/laravel-mix/laravel-mix/issues/1942#issuecomment -998148038 1. Install ` global first` - npm:`npm install fast-glob -D` - yarn:`yarn add fast-glob -D` 2. Then change 'tailwind. config. js' to: ```js module.exports = { //Look here content: require('fast-glob').sync([ './ src/**/*. {html,js,ts}', './ node_modules/tw-elements/dist/js/**/*.js', './ theme/**/*.php' ]), theme: { extend: {}, }, plugins: [], } ``` And then it was perfectly solved
Swiper.js reports an error: Uncaught TypeError: Cannot read properties of undefined (reading 'onTouchEnd') at Swiper.onTouchEnd Author: Chuwen Time: 2021-11-30 Classification: JavaScript comment Uncaught TypeError: Cannot read properties of undefined (reading 'onTouchEnd') at Swiper.onTouchEnd ! [Uncaught TypeError: Cannot read properties of undefined (reading 'onTouchEnd') at Swiper.onTouchEnd]( https://cdn.nowtime.cc/2021/11/30/1438435762.png ) When I was puzzled and thought that I had changed the 'freeMode' parameter part, and then caused manual sliding, I reported this error. The reason is that the module is imported by module, and the 'freeMode' module is not imported. You only need to import and use it: ```js import 'swiper/css'; import Swiper, {Autoplay, FreeMode} from 'swiper'; Swiper.use([Autoplay, FreeMode]); ```
Solve the problem that Swiper.js unlimited rolling (running lights) will interfere with the movement effect after manual sliding Author: Chuwen Time: 2021-11-30 Classification: JavaScript comment ###Expected effect After sliding left and right, release the mouse/hand and move according to the initial moving direction, and the moving speed cannot change too much ###The solution is: Set the 'freeMode. momentumRatio' to a smaller value, such as' 0.01` Set 'freeMode. momentumBounce' to 'false` Online preview: https://codepen.io/printnow/pen/ZEXEajW **FreeMode * * Parameters: |Parameter | Type | Default Value | Remarks| | ------------------------------------------------------------ | --------------------------- | ------ | ------------------------------------------------------------ | | [enabled]( https://swiperjs.com/swiper-api#param -FreeMode enabled) | ` boolean | FreeModeOptions ` | Enable the free mode function. The free mode parameter or boolean value of the object is' true 'to enable the default setting| | [minimumVelocity]( https://swiperjs.com/swiper-api#param -FreeMode minimumVelocity) | ` number ` | 0.02 | The minimum contact movement speed required to trigger free mode momentum| | [momentum]( https://swiperjs.com/swiper-api#param -FreeMode momentum) | ` boolean '| true | If enabled, the slider will continue to move for some time after releasing it| | **[momentumBounce]( https://swiperjs.com/swiper-api#param -FreeMode momentumBounce) * * | ` boolean '| true | If you want to disable momentum bounce in free mode, please set it to ` false'| | [momentumBounceRatio]( https://swiperjs.com/swiper-api#param -FreeMode momentumBounceRatio) | ` number '| 1 | The higher the value, the greater the momentum rebound effect| | **[momentumRatio]( https://swiperjs.com/swiper-api#param -FreeMode momentumRatio) * * | ` number ` | 1 | After the slider is released, the greater the value, the greater the momentum distance| | [momentumVelocityRatio]( https://swiperjs.com/swiper-api#param -FreeMode momentumVelocityRatio) | ` number '| 1 | After the slider is released, the higher the value, the greater the momentum speed| | [sticky]( https://swiperjs.com/swiper-api#param -FreeMode sticky) | ` boolean '| false | Set to ` true' to enable capturing slide position in free mode (` freeMode ')| ###JS code: >If you import by module, you must import the 'FreeMode' module! ```js import 'swiper/css'; import Swiper, {Autoplay, FreeMode} from 'swiper'; Swiper.use([Autoplay, FreeMode]); let itemCount = parseInt(u('.swiper-wrapper').data('item-count')); const swiper = new Swiper("#reviews-list", { width: window.innerWidth, resistanceRatio: 0, speed: 10000, observer: true, observeParents: true, slidesPerGroup: 1, // autoplay autoplay: { Delay: 0,//Interval after each picture is moved DisableOnInteraction: false//Whether to stop automatic movement after touching }, freeMode: { enabled: true, MomentumBounce: false,//mainly these two parameters MomentumRatio: 0.01//Mainly these two parameters },//Not fit // loop Loop: true,//loop // grid centeredSlides: true, slidesPerView: 'auto',//5 spaceBetween: 25, loopedSlides: itemCount, loopAdditionalSlides: itemCount, }); ``` ####HTML code example: ```html <! doctype html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Switch.js unlimited running lamp</title> <link rel="stylesheet" href=" https://cdn.jsdelivr.net/npm/swiper @7.3.1/swiper-bundle.min.css"/> <script src=" https://cdn.jsdelivr.net/npm/swiper @7.3.1/swiper-bundle.min.js"></script> <style> #review-list { width: 100%; height: 100%; } .review-item { width: 300px; height: 180px; background-color: #ff4081; color: white; display: flex; align-items: center; justify-content: space-around; } </style> </head> <body> <div id="review-list"> <div class="swiper-wrapper"> <div class="review item swiper slide">Comment 1</div> <div class="review item swiper slide">Comment 2</div> <div class="review item swiper slide">Comment 3</div> <div class="review item swiper slide">Comment 4</div> <div class="review item swiper slide">Comment 5</div> <div class="review item swiper slide">Comment 6</div> <div class="review item swiper slide">Comment 7</div> <div class="review item swiper slide">Comment 8</div> <div class="review item swiper slide">Comment 9</div> <div class="review item swiper slide">Comment 10</div> </div> </div> <script> const swiper = new Swiper("#review-list", { width: window.innerWidth, resistanceRatio: 0, speed: 10000, observer: true, observeParents: true, slidesPerGroup: 1, // autoplay autoplay: { Delay: 0,//Interval after each picture is moved DisableOnInteraction: false//Whether to stop automatic movement after touching }, freeMode: { enabled: true, momentumBounce: false, momentumRatio: 0.01, momentumVelocityRatio: 0.01 },//Not fit // loop Loop: true,//loop // grid centeredSlides: true, slidesPerView: 'auto',//5 spaceBetween: 25, }); </script> </body> </html> ```