Though localization is the primary use, it can be used to make any data available to your script that you can normally only get from the server side of WordPress.
<?php wp_localize_script( $handle, $name, $data ); ?>
(string) (必填) The registered script handle you are attaching the data for.
<script> tag containing your localization variable occurs at the time that the enqueued script is printed (output/included on the page). This has some significant repercussions if you enqueue your script as you should using the appropriate 动作s (wp_enqueue_scripts and admin_enqueue_scripts), but wish to localize later using data that is not available at enqueue time.
In this case, consider enqueueing your script with the in_footer argument set to true, to delay the printing of your script include until much later in the page build (ie:
wp_enqueue_script( $slug, $URL, $deps, $ver, true ); ). The last chance to localize your script would then be on the 'wp_print_footer_scripts' hook.