simple example for using require.js

后端 未结 3 632
广开言路
广开言路 2021-01-31 04:44

I am trying to learn how to use require.js. So I made an HTML page with the following tags in the body.



        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 05:21

    the contents of the main file should be a require call. for example, you have a values.js module containing:

    define({
        color: "black",
        size : "large"
    });
    

    in your main file (shirt.js), load the values.js as a dependency (assuming they are in the same directory):

    require(['values'],function(values){
        //values.color
        //values.size
    });
    

提交回复
热议问题