视口数据


目录

命名空间:core/viewport。

选择器

isViewportMatch

如果视口匹配给定的查询则返回 true,否则返回 false。

用法

import { store as viewportStore } from '@wordpress/viewport';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
const ExampleComponent = () => {
	const isMobile = useSelect(
		( select ) => select( viewportStore ).isViewportMatch( '< small' ),
		[]
	);

	return isMobile ? (
		<div>{ __( 'Mobile' ) }</div>
	) : (
		<div>{ __( 'Not Mobile' ) }</div>
	);
};

参数

返回值

操作

此包中的操作不应直接使用。

暂无内容。


版本号 #2
由 壳壳虫 创建于 2026-03-26 17:08:43 UTC
由 壳壳虫 更新于 2026-03-26 17:08:43 UTC