小编Aut*_*oxy的帖子

链接并执行GitHub上托管的外部JavaScript文件

当我尝试将本地JavaScript文件的链接引用更改为GitHub原始版本时,我的测试文件停止工作.错误是:

拒绝从...执行脚本,因为它的MIME类型(text/plain)不可执行,并且启用了严格的MIME类型检查.

有没有办法禁用此行为或是否有允许链接到GitHub原始文件的服务?

工作代码:

<script src="bootstrap-wysiwyg.js"></script>
Run Code Online (Sandbox Code Playgroud)

非工作代码:

<script src="https://raw.github.com/mindmup/bootstrap-wysiwyg/master/bootstrap-wysiwyg.js"></script>
Run Code Online (Sandbox Code Playgroud)

javascript github

525
推荐指数
8
解决办法
15万
查看次数

打字稿 typeof 字符串不能按预期工作

谁能解释为什么第二个变体不起作用?这是一个错误吗?

const prints = (s: string): void => console.log(s);
var x: string | number = Date.now() % 2 ? "test" : 5;

// 1st: working
if (typeof x === "string") {
  prints(x);
}

// 2nd: not working
var typex = typeof x === "string";
if (typex) {
  prints(x);
}

Run Code Online (Sandbox Code Playgroud)

第二个变体显示以下错误:

'string | 类型的参数 number' 不能分配给类型为 'string' 的参数。“数字”类型不能分配给“字符串”类型

TS游乐场

javascript string typeof typescript

6
推荐指数
1
解决办法
86
查看次数

React hook 表单方法 - setValue - 不起作用

我有一些可清除的选择,我想将applets状态字段重置为空数组。

const defaultFormValues = { device: { ...initialDevice }, applets: [] };
  const { control, getValues, setValue, reset, handleSubmit } = useForm<CreateDeviceFormData>({
    mode: "all",
    reValidateMode: "onChange",
    defaultValues: defaultFormValues,
    resolver: yupResolver(validationSchema),
  });

  const onChangeHandler = React.useCallback(
    (value: Experience | null) => {
      if (value) {
        setValue("applets", getApplets(value));
      } else {
        setValue("applets", []);
        // reset(defaultFormValues);
      }

      setValue("device.experience_id", value ? value.id : undefined);
    },
    [templateSelector, setValue],
  );

  console.log("current data", getValues(), control);
  return (
    <>
      <SomeAutocompleteComponent control={control} onChange={onChangeHandler} />
      <SelectAppletsComponent control={control} /> …
Run Code Online (Sandbox Code Playgroud)

javascript frontend reactjs react-hooks react-hook-form

3
推荐指数
1
解决办法
1万
查看次数