资讯专栏INFORMATION COLUMN

Webpack入门——使用Webpack打包Angular项目的一个例子

pakolagij / 1532人阅读

摘要:一什么是是一个前端的模块管理工具,以下是的官网,一进入官网可以看到下面这张大图这张图基本上解释了是用来干嘛的,将一些相互依赖的模块文件,打包成一个或多个文件,减少请求次数,提升性能。希望这篇文章可以帮助大家入门。

(一)什么是Webpack

  Webpack是一个前端的模块管理工具(module bundler),以下是webpack的官网:http://webpack.github.io/,一进入官网可以看到下面这张大图:

这张图基本上解释了webpack是用来干嘛的,将一些相互依赖的模块(文件),打包成一个或多个js文件,减少http请求次数,提升性能。这些相互依赖的模块可以是图片、字体、coffee文件、样式文件、less文件等。

  具体怎么用呢?接下来我将用一个例子来说明:

(二)一个Webpack+Angular的例子 1.先看下目录结构

2.安装Webpack及其他组件

安装Webpack之前建议先安装Node.js,然后采用npm的方式来安装Webpack:

npm install webpack -g

因为要用到angular,所以要安装angular:

npm install angular

还要安装一系列加载器(loader):

npm install style-loader css-loader url-loader sass-loader raw-loader

注意:除了webpack是全局安装之外,其他组件都是安装在app文件夹下面,会自动生成node_modules文件夹。

3.配置文件webpack.config.js
 1 module.exports = {
 2   context: __dirname + "/app",//上下文
 3   entry: "./index.js",//入口文件
 4   output: {//输出文件
 5     path: __dirname + "/app",
 6     filename: "./bundle.js"
 7   },
 8   module: {
 9     loaders: [//加载器
10       {test: /.html$/, loader: "raw"},
11       {test: /.css$/, loader: "style!css"},
12       {test: /.scss$/, loader: "style!css!sass"},
13       {test: /.(png|jpg|ttf)$/, loader: "url?limit=8192"}
14     ]
15   }
16 };
4.入口文件index.js
1 var angular = require("angular");//引入angular
2 var ngModule = angular.module("app",[]);//定义一个angular模块
3 require("./directives/hello-world/hello-world.js")(ngModule);//引入指令(directive)文件
4 require("./css/style.css");//引入样式文件

require用于引入外部模块(可以是对象,可以是函数,可以是css样式,可以是html页面等)

5.主页面index.html
 1
 2 
 3 
 4   
 5   Angular with Webpacktitle>
 6 </head>
 7 <body>
 8   <h1>Angular + Webpack</h1>
 9   <hello-world></hello-world>
10   <script src="bundle.js"></script>
11 </body>
12 </html></pre>
<p>可以看到主页面是非常干净清爽的,只引入了一个输出文件bundle.js,然后html标签里加了ng-app="app"。</p>
<b>6.指令文件hello-world.js</b>
<pre> 1 module.exports = function(ngModule) {
 2   ngModule.directive("helloWorld", helloWorldFn);//定义指令,对应页面中的
 3   require("./hello-world.scss");
 4   function helloWorldFn() {
 5     return {
 6       restrict: "E",//元素(element)
 7       scope: {},
 8       template: require("./hello-world.html"),//模板
 9       //templateUrl: "directives/hello-world/hello-world.html",
10       controllerAs: "vm",// <=> $scope.vm = {greeting: "你好,我是卡哥"}
11       controller: function () {
12         var vm = this;
13         vm.greeting = "你好,我是卡哥,很高兴见到你";
14       }
15     }
16   }
17 }</pre>
<p>module.exports用于将模块(文件)作为一个接口(一般是一个函数)暴露给外部。</p>
<b>7.其他文件(style.css、hello-world.html、hello-world.scss)</b>
<pre> 1 @font-face{
 2     font-family: "maozedong";
 3     src: url(../fonts/maozedong.ttf);
 4 }
 5 body{
 6     background: url(../images/longmao.jpg) yellowgreen;
 7     font-size: 24pt;
 8     color: #fff;
 9     font-family: "maozedong";
10 }</pre>
<pre>1 <div class="hello-world">
2   {{vm.greeting}}
3 </div></pre>
<pre>1 .hello-world {
2   color: red;
3   border: 1px solid green;
4 }</pre>
<b>8.编译和运行</b>
<p>在命令行工具中输入:webpack,即可编译,这时我们会遇到第一个坑:</p>
<p><script type="text/javascript">showImg("https://segmentfault.com/img/bVsumR");</script></p>
<p>这个错误的关键行在"You may need an appropriate loader to handle the file type",大概意思就是你的加载器(loader)不正确,可是我们明明安装上了所有的加载器啊,也在配置文件中引用了呀,我在网上找了很久都没找到问题所在,后来还是一位细心的同事帮我解决这个问题的,原来问题出在配置文件中的"module"下的"loader"应该是"loaders",就因为少了一个"s",浪费我一上午的时间。</p>
<p>修改过来之后,编译通过了,我们在浏览器中打开主页面index.html,这时遇到了第二个坑:</p>
<p><script type="text/javascript">showImg("https://segmentfault.com/img/bVsumY");</script></p>
<p>大概意思是你跨域了,不能加载hello-world.html这个文件,问题出在指令文件hello-world.js中的引用模板地址的代码:</p>
<p>templateUrl: "directives/hello-world/hello-world.html"</p>
<p>在网上搜到一个解决办法,就是使用Node.js自带的的http-server,以下是server.js的代码:</p>
<p><script type="text/javascript">showImg("https://segmentfault.com/img/bVsum2");</script></p>
<p>使用之前要先安装express:npm install express,然后在命令行工具中输入node server.js开启服务,这时在浏览器中输入:localhost:8000/index.html即可访问主页面。</p>
<p>另外一个方法是用require的方式引入hello-world.html:</p>
<p>template: require("./hello-world.html")</p>
<b>(三)补充</b>

<p>(1)编译的命令"webpack"后面可以加参数,如:</p>
<p>"webpack -p"表示对打包后的文件进行压缩</p>
<p>"webpack -w"表示实时进行打包更新</p>
<p>"webpack -d"表示提供source map,方便调试</p>
<p>(2)webpack-dev-server可以提供实时监视文件变化的功能,使用之前先安装webpack-dev-server:</p>
<p>npm install webpack-dev-server -g</p>
<p>然后在命令行中输入:webpack-dev-server --progress --colors,显示以下结果:</p>
<p><script type="text/javascript">showImg("https://segmentfault.com/img/bVsum4");</script></p>
<p>这时在浏览器中输入:localhost:8080(localhost:8080/webpack-dev-server),你对静态资源的任何改动都会直接反映到主页面中。</p>
<p>--------------------------------------------------------- 华丽的分割线 ------------------------------------------------</p>
<p>总结:这是一个Webpack+Angular的典型例子,包含了最基本的打包js文件、css文件、scss文件、图片、字体的方法。通过这几天对Webpack的学习,发现有关Webpack的资料确实是非常少的,百度百科和维基百科上甚至都没有这个词条。希望这篇文章可以帮助大家入门。</p>           
               
                                           
                       
                 </div>
            
                     <div class="mt-64 tags-seach" >
                 <div class="tags-info">
                                                                                                                    
                         <a style="width:120px;" title="服务器托管" href="https://www.ucloud.cn/site/product/uhybrid.html">服务器托管</a>
                                             
                         <a style="width:120px;" title="专线服务" href="https://www.ucloud.cn/site/active/network.html?ytag=seo">专线服务</a>
                                                                                                                                                 
                                      
                     
                    
                                                                                               <a style="width:120px;" title="Webpack打包分块" href="https://www.ucloud.cn/yun/tag/Webpackdabaofenkuai/">Webpack打包分块</a>
                                                                                                           <a style="width:120px;" title="webpack入门" href="https://www.ucloud.cn/yun/tag/webpackrumen/">webpack入门</a>
                                                                                                           <a style="width:120px;" title="webpack使用" href="https://www.ucloud.cn/yun/tag/webpackshiyong/">webpack使用</a>
                                                                                                           <a style="width:120px;" title="webpack 使用公用cdn" href="https://www.ucloud.cn/yun/tag/webpack shiyonggongyongcdn/">webpack 使用公用cdn</a>
                                                         
                 </div>
               
              </div>
             
               <div class="entry-copyright mb-30">
                   <p class="mb-15"> 文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。</p>
                 
                   <p>转载请注明本文地址:https://www.ucloud.cn/yun/78576.html</p>
               </div>
                      
               <ul class="pre-next-page">
                 
                                  <li class="ellipsis"><a class="hpf" href="https://www.ucloud.cn/yun/78575.html">上一篇:匿名函数预解析思考</a></li>  
                                                
                                       <li class="ellipsis"><a class="hpf" href="https://www.ucloud.cn/yun/78577.html">下一篇:JavaScript 表单脚本——“选择框脚本”的注意要点</a></li>
                                  </ul>
              </div>
              <div class="about_topicone-mid">
                <h3 class="top-com-title mb-0"><span data-id="0">相关文章</span></h3>
                <ul class="com_white-left-mid atricle-list-box">
                             
                                                                                                    <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/38106.html"><b>让 <em>Angular</em> 1.x 跟上时代<em>的</em>步伐</b></a></h2>
                                                     <p class="ellipsis2 good">摘要:所以说的模块机制没有解决文件依赖关系和文件异步加载的问题。大部分团队还是停留在第二第三阶段,每个阶段的实现都有很多种选择。希望这篇文章能够激起大家永远保持积极向前追求完美代码的心,不仅对自己的成长也会对公司带来无限的价值。

本篇技术博客来自有着化腐朽为神奇能力的,Worktile 技术牛人Web 总监 @徐海峰 大神的分享~满满的干货,你值得拥有!
Worktile 的前端构建之路
2...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-21.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/00/small_000000021.jpg" alt=""><span class="layui-hide64">李增田</span></a>
                                    <time datetime="">2019-07-25 10:41</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                                       <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/87792.html"><b><em>webpack</em> 教程资源收集</b></a></h2>
                                                     <p class="ellipsis2 good">学习的过程中收藏了这些优秀教程和的项目,希望对你有帮助。 github地址, 有不错的就更新

官方文档
中文指南


 初级教程

webpack-howto  作者:Pete Hunt
Webpack 入门指迷  作者:题叶   
webpack-demos 作者:ruanyf
一小时包教会 —— webpack 入门指南  作者:VaJoy Larn  
webpack 入门及实践  作者:...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-885.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/08/small_000000885.jpg" alt=""><span class="layui-hide64">Backache</span></a>
                                    <time datetime="">2019-08-21 14:05</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                                       <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/90203.html"><b><em>webpack</em> 3 零基础<em>入门</em>教程 #1 - 介绍</b></a></h2>
                                                     <p class="ellipsis2 good">摘要:所以它在某些程度上,跟的功能有些相同。严格上讲,模块化不是他强调的东西,他旨在规范前端开发流程。更是明显强调模块化开发,而那些文件压缩合并预处理等功能,不过是他附带的功能。

1. webpack 是什么?
showImg(https://segmentfault.com/img/remote/1460000012293461);
先来说一下 webpack 是什么。
webpack 的...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-16.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/00/small_000000016.jpg" alt=""><span class="layui-hide64">张红新</span></a>
                                    <time datetime="">2019-08-21 17:55</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                                       <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/89440.html"><b>基于<em>webpack</em>构建<em>的</em><em>angular</em> 1.x 工程(一)<em>webpack</em>篇</b></a></h2>
                                                     <p class="ellipsis2 good">摘要:基于构建的工程一篇现在都已经出到的版本了,可我对它的认识还是停留在的版本。然后是写启动的命令行,也就是上面的这样写的意思是,当你输入你的命令名字就会让执行你对应命令的语句。我们首先把基本的配置引进来。

基于webpack构建的angular 1.x 工程(一)webpack篇
  现在AngularJS都已经出到4.x的版本了,可我对它的认识还是停留在1.x的版本。    之前用它是为...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-1179.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/11/small_000001179.jpg" alt=""><span class="layui-hide64">Anleb</span></a>
                                    <time datetime="">2019-08-21 17:23</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                           
                </ul>
              </div>
              
               <div class="topicone-box-wangeditor">
                  
                  <h3 class="top-com-title mb-64"><span>发表评论</span></h3>
                   <div class="xcp-publish-main flex_box_zd">
                                      
                      <div class="unlogin-pinglun-box">
                        <a href="javascript:login()" class="grad">登陆后可评论</a>
                      </div>                   </div>
               </div>
              <div class="site-box-content">
                <div class="site-content-title">
                  <h3 class="top-com-title mb-64"><span>0条评论</span></h3>   
                </div> 
                      <div class="pages"></ul></div>
              </div>
           </div>
           <div class="layui-col-md4 layui-col-lg3 com_white-right site-wrap-right">
              <div class=""> 
                <div class="com_layuiright-box user-msgbox">
                    <a href="https://www.ucloud.cn/yun/u-973.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/09/small_000000973.jpg" alt=""></a>
                    <h3><a href="https://www.ucloud.cn/yun/u-973.html" rel="nofollow">pakolagij</a></h3>
                    <h6>男<span>|</span>高级讲师</h6>
                    <div class="flex_box_zd user-msgbox-atten">
                     
                                                                      <a href="javascript:attentto_user(973)" id="attenttouser_973" class="grad follow-btn notfollow attention">我要关注</a>
      
                                                                                        <a href="javascript:login()" title="发私信" >我要私信</a>
                     
                                            
                    </div>
                    <div class="user-msgbox-list flex_box_zd">
                          <h3 class="hpf">TA的文章</h3>
                          <a href="https://www.ucloud.cn/yun/ut-973.html" class="box_hxjz">阅读更多</a>
                    </div>
                      <ul class="user-msgbox-ul">
                                                  <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/120622.html">怎么连接云主机ip-云主机怎么使用?</a></h3>
                            <p>阅读 2901<span>·</span>2021-09-22 15:50</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/119831.html">MIT 在聚变能源方面取得重大进展</a></h3>
                            <p>阅读 3121<span>·</span>2021-09-10 10:51</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/114145.html">在一个元素上:hover,改变另一个元素的css属性</a></h3>
                            <p>阅读 2980<span>·</span>2019-08-29 17:10</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/108279.html">JavaScript面向对象中的原型个人分享</a></h3>
                            <p>阅读 2782<span>·</span>2019-08-26 12:14</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/107994.html">仿"米丫天气App"-Vue项目总结</a></h3>
                            <p>阅读 1731<span>·</span>2019-08-26 12:00</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/107473.html">ABAP开发人员未来应该学些什么</a></h3>
                            <p>阅读 731<span>·</span>2019-08-26 11:44</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/107462.html">javascript填充用户的默认头像,支持Vue.js</a></h3>
                            <p>阅读 553<span>·</span>2019-08-26 11:44</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/107358.html">[翻译]了解NodeJS看这一篇就够了</a></h3>
                            <p>阅读 2700<span>·</span>2019-08-26 11:41</p></li>
                                                
                      </ul>
                </div>

                   <!-- 文章详情右侧广告-->
              
  <div class="com_layuiright-box">
                  <h6 class="top-com-title"><span>最新活动</span></h6> 
           
         <div class="com_adbox">
                    <div class="layui-carousel" id="right-item">
                      <div carousel-item>
                                                                                                                       <div>
                          <a href="https://www.ucloud.cn/site/product/uhost.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220620/Z7TLrpAi.png" alt="云服务器">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/product/uhybrid.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220620/MWraMsBh.png" alt="混合云">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/product/ucloudstack.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220620/ifzOxvjW.png" alt="私有云">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/product/utrion.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220620/VDqwC1iN.png" alt="超融合服务器">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/product/uhybrid.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220630/pJwnviKN.png" alt="服务器托管">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/product/uxzone.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220630/CDb5uXxp.jpeg" alt="idc机房托管">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/active/network.html?ytag=seo"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/230227/XWsSXmvm.png" alt="专线服务">                                 
                          </a>
                        </div>
                                                                   
                    
                        
                      </div>
                    </div>
                      
                    </div>                    <!-- banner结束 -->
              
<div class="adhtml">

</div>
                <script>
                $(function(){
                    $.ajax({
                        type: "GET",
                                url:"https://www.ucloud.cn/yun/ad/getad/1.html",
                                cache: false,
                                success: function(text){
                                  $(".adhtml").html(text);
                                }
                        });
                    })
                </script>                </div>              </div>
           </div>
        </div>
      </div> 
    </section>
    <!-- wap拉出按钮 -->
     <div class="site-tree-mobile layui-hide">
      <i class="layui-icon layui-icon-spread-left"></i>
    </div>
    <!-- wap遮罩层 -->
    <div class="site-mobile-shade"></div>
    
       <!--付费阅读 -->
       <div id="payread">
         <div class="layui-form-item">阅读需要支付1元查看</div>  
         <div class="layui-form-item"><button class="btn-right">支付并查看</button></div>     
       </div>
      <script>
      var prei=0;

       
       $(".site-seo-depict pre").each(function(){
          var html=$(this).html().replace("<code>","").replace("</code>","").replace('<code class="javascript hljs" codemark="1">','');
          $(this).attr('data-clipboard-text',html).attr("id","pre"+prei);
          $(this).html("").append("<code>"+html+"</code>");
         prei++;
       })
           $(".site-seo-depict img").each(function(){
             
            if($(this).attr("src").indexOf('data:image/svg+xml')!= -1){
                $(this).remove();
            }
       })
     $("LINK[href*='style-49037e4d27.css']").remove();
       $("LINK[href*='markdown_views-d7a94ec6ab.css']").remove();
layui.use(['jquery', 'layer','code'], function(){
  $("pre").attr("class","layui-code");
      $("pre").attr("lay-title","");
       $("pre").attr("lay-skin","");
  layui.code(); 
       $(".layui-code-h3 a").attr("class","copycode").html("复制代码 ").attr("onclick","copycode(this)");
      
});
function copycode(target){
    var id=$(target).parent().parent().attr("id");
  
                  var clipboard = new ClipboardJS("#"+id);

clipboard.on('success', function(e) {


    e.clearSelection();
    alert("复制成功")
});

clipboard.on('error', function(e) {
    alert("复制失败")
});
}
//$(".site-seo-depict").html($(".site-seo-depict").html().slice(0, -5));
</script>
  <link rel="stylesheet" type="text/css" href="https://www.ucloud.cn/yun/static/js/neweditor/code/styles/tomorrow-night-eighties.css">
    <script src="https://www.ucloud.cn/yun/static/js/neweditor/code/highlight.pack.js" type="text/javascript"></script>
    <script src="https://www.ucloud.cn/yun/static/js/clipboard.js"></script>

<script>hljs.initHighlightingOnLoad();</script>

<script>
    function setcode(){
        var _html='';
    	  document.querySelectorAll('pre code').forEach((block) => {
        	  var _tmptext=$.trim($(block).text());
        	  if(_tmptext!=''){
        		  _html=_html+_tmptext;
        		  console.log(_html);
        	  }
    		 
    		  
    		 
      	  });
    	 

    }

</script>

<script>
function payread(){
  layer.open({
      type: 1,
      title:"付费阅读",
      shadeClose: true,
      content: $('#payread')
    });
}
// 举报
function jupao_tip(){
  layer.open({
      type: 1,
      title:false,
      shadeClose: true,
      content: $('#jubao')
    });

}
$(".getcommentlist").click(function(){
var _id=$(this).attr("dataid");
var _tid=$(this).attr("datatid");
$("#articlecommentlist"+_id).toggleClass("hide");
var flag=$("#articlecommentlist"+_id).attr("dataflag");
if(flag==1){
flag=0;
}else{
flag=1;
//加载评论
loadarticlecommentlist(_id,_tid);
}
$("#articlecommentlist"+_id).attr("dataflag",flag);

})
$(".add-comment-btn").click(function(){
var _id=$(this).attr("dataid");
$(".formcomment"+_id).toggleClass("hide");
})
$(".btn-sendartcomment").click(function(){
var _aid=$(this).attr("dataid");
var _tid=$(this).attr("datatid");
var _content=$.trim($(".commenttext"+_aid).val());
if(_content==''){
alert("评论内容不能为空");
return false;
}
var touid=$("#btnsendcomment"+_aid).attr("touid");
if(touid==null){
touid=0;
}
addarticlecomment(_tid,_aid,_content,touid);
})
 $(".button_agree").click(function(){
 var supportobj = $(this);
         var tid = $(this).attr("id");
         $.ajax({
         type: "GET",
                 url:"https://www.ucloud.cn/yun/index.php?topic/ajaxhassupport/" + tid,
                 cache: false,
                 success: function(hassupport){
                 if (hassupport != '1'){






                         $.ajax({
                         type: "GET",
                                 cache:false,
                                 url: "https://www.ucloud.cn/yun/index.php?topic/ajaxaddsupport/" + tid,
                                 success: function(comments) {

                                 supportobj.find("span").html(comments+"人赞");
                                 }
                         });
                 }else{
                	 alert("您已经赞过");
                 }
                 }
         });
 });
 function attenquestion(_tid,_rs){
    	$.ajax({
    //提交数据的类型 POST GET
    type:"POST",
    //提交的网址
    url:"https://www.ucloud.cn/yun/favorite/topicadd.html",
    //提交的数据
    data:{tid:_tid,rs:_rs},
    //返回数据的格式
    datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
    //在请求之前调用的函数
    beforeSend:function(){},
    //成功返回之后调用的函数
    success:function(data){
    	var data=eval("("+data+")");
    	console.log(data)
       if(data.code==2000){
    	layer.msg(data.msg,function(){
    	  if(data.rs==1){
    	      //取消收藏
    	      $(".layui-layer-tips").attr("data-tips","收藏文章");
    	      $(".layui-layer-tips").html('<i class="fa fa-heart-o"></i>');
    	  }
    	   if(data.rs==0){
    	      //收藏成功
    	      $(".layui-layer-tips").attr("data-tips","已收藏文章");
    	      $(".layui-layer-tips").html('<i class="fa fa-heart"></i>')
    	  }
    	})
    	 
       }else{
    	layer.msg(data.msg)
       }


    }   ,
    //调用执行后调用的函数
    complete: function(XMLHttpRequest, textStatus){
     	postadopt=true;
    },
    //调用出错执行的函数
    error: function(){
        //请求出错处理
    	postadopt=false;
    }
 });
}
</script>
<footer>
        <div class="layui-container">
            <div class="flex_box_zd">
              <div class="left-footer">
                    <h6><a href="https://www.ucloud.cn/"><img src="https://www.ucloud.cn/yun/static/theme/ukd//images/logo.png" alt="UCloud (优刻得科技股份有限公司)"></a></h6>
                    <p>UCloud (优刻得科技股份有限公司)是中立、安全的云计算服务平台,坚持中立,不涉足客户业务领域。公司自主研发IaaS、PaaS、大数据流通平台、AI服务平台等一系列云计算产品,并深入了解互联网、传统企业在不同场景下的业务需求,提供公有云、混合云、私有云、专有云在内的综合性行业解决方案。</p>
              </div>
              <div class="right-footer layui-hidemd">
                  <ul class="flex_box_zd">
                      <li>
                        <h6>UCloud与云服务</h6>
                         <p><a href="https://www.ucloud.cn/site/about/intro/">公司介绍</a></p>
                         <p><a href="https://zhaopin.ucloud.cn/" >加入我们</a></p>
                         <p><a href="https://www.ucloud.cn/site/ucan/onlineclass/">UCan线上公开课</a></p>
                         <p><a href="https://www.ucloud.cn/site/solutions.html" >行业解决方案</a></p>                                                  <p><a href="https://www.ucloud.cn/site/pro-notice/">产品动态</a></p>
                      </li>
                      <li>
                        <h6>友情链接</h6>                                             <p><a href="https://www.compshare.cn/?ytag=seo">GPU算力平台</a></p>                                             <p><a href="https://www.ucloudstack.com/?ytag=seo">UCloud私有云</a></p>
                                             <p><a href="https://www.surfercloud.com/">SurferCloud</a></p>                                             <p><a href="https://www.uwin-link.com/">工厂仿真软件</a></p>                                             <p><a href="https://pinex.it/">Pinex</a></p>                                             <p><a href="https://www.picpik.ai/zh">AI绘画</a></p>
                                             
                      </li>
                      <li>
                        <h6>社区栏目</h6>
                         <p><a href="https://www.ucloud.cn/yun/column/index.html">专栏文章</a></p>
                     <p><a href="https://www.ucloud.cn/yun/udata/">专题地图</a></p>                      </li>
                      <li>
                        <h6>常见问题</h6>
                         <p><a href="https://www.ucloud.cn/site/ucsafe/notice.html" >安全中心</a></p>
                         <p><a href="https://www.ucloud.cn/site/about/news/recent/" >新闻动态</a></p>
                         <p><a href="https://www.ucloud.cn/site/about/news/report/">媒体动态</a></p>                                                  <p><a href="https://www.ucloud.cn/site/cases.html">客户案例</a></p>                                                
                         <p><a href="https://www.ucloud.cn/site/notice/">公告</a></p>
                      </li>
                      <li>
                          <span><img src="https://static.ucloud.cn/7a4b6983f4b94bcb97380adc5d073865.png" alt="优刻得"></span>
                          <p>扫扫了解更多</p></div>
            </div>
            <div class="copyright">Copyright © 2012-2023 UCloud 优刻得科技股份有限公司<i>|</i><a rel="nofollow" href="http://beian.miit.gov.cn/">沪公网安备 31011002000058号</a><i>|</i><a rel="nofollow" href="http://beian.miit.gov.cn/"></a> 沪ICP备12020087号-3</a><i>|</i> <script type="text/javascript" src="https://gyfk12.kuaishang.cn/bs/ks.j?cI=197688&fI=125915" charset="utf-8"></script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?290c2650b305fc9fff0dbdcafe48b59d";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZSMXQ3P9N"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-DZSMXQ3P9N');
</script>
<script>
(function(){
var el = document.createElement("script");
el.src = "https://lf1-cdn-tos.bytegoofy.com/goofy/ttzz/push.js?99f50ea166557aed914eb4a66a7a70a4709cbb98a54ecb576877d99556fb4bfc3d72cd14f8a76432df3935ab77ec54f830517b3cb210f7fd334f50ccb772134a";
el.id = "ttzz";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(el, s);
})(window)
</script></div> 
        </div>
    </footer>
</body>
<script src="https://www.ucloud.cn/yun/static/theme/ukd/js/common.js"></script>
<<script type="text/javascript">
$(".site-seo-depict *,.site-content-answer-body *,.site-body-depict *").css("max-width","100%");
</script>
</html>