requirejs可以通过http加载js吗

查看:342
本文介绍了requirejs可以通过http加载js吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

requirejs可以通过http加载js吗,
比如:require("http://api.baidu.com/map/1.2.js")

解决方案

支持的!
支持与否,为啥不自己试试呢?

但是不是你那样写的,要先配置。

require.config({
  paths:{
    'baiduapi':'http://api.baidu.com/map/1.2.js'
  }
});
//调用
require('baiduapi');

可以参考这里:
http://requirejs.org/docs/api.html#confi...

There may be times when you do want to reference a script directly and not conform to the "baseUrl + paths" rules for finding it. If a module ID has one of the following characteristics, the ID will not be passed through the "baseUrl + paths" configuration, and just be treated like a regular URL that is relative to the document:
Ends in ".js".
Starts with a "/".
Contains an URL protocol, like "http:" or "https:".

顺便推荐一下,我写的模块加载,实现原理和require,seajs之类的不一致。


https://github.com/donghanji/pm

也是支持url的方式加载模块的。

这篇关于requirejs可以通过http加载js吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆