如何将变量从popup.js发送到内容脚本? 例如在我的popup.js上
Set-AuthenticodeSignature
如何发送using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlendShapesController : MonoBehaviour
{
private SkinnedMeshRenderer bodySkinnedMeshRenderer;
// Start is called before the first frame update
void Start()
{
bodySkinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>();
}
// Update is called once per frame
void Update()
{
int rand = Random.Range(0, 23);
bodySkinnedMeshRenderer.SetBlendShapeWeight(0, rand);
}
}
,name = documente.getelementbyid("name")
car= documente.getelementbyid("car")
age= documente.getelementbyid("age")
和name
到我的内容脚本?
我不明白该如何传递消息
答案 0 :(得分:0)
您需要将这些文件从一个文件导出/导入到另一个文件。
popup.js
export const name = document.getElementbyId("name");
content.js
import { name } from './popup';
console.log(name) //=> dom element you selected
或者,甚至可以更好地创建一个函数,该函数将返回所需的值,将其导入并调用内容文件
popup.js
export const getElementX = el => document.getElementById(el);
content.js
import { getElement } from './popup';
const name = getElement('name')
console.log(name) //=> dom element you selected
否则,您可以修改函数以返回准备好的元素数组,或者您需要的任何内容。
如果您在节点环境中,只需使用commonJS格式而不是上面显示的ESM。
答案 1 :(得分:-1)
不起作用,因为我需要从弹出窗口中导出,并且该模块仅在弹出窗口中起作用