多页面应用开发模式主页面引入所有入口文件

问题:多页面应用开发模式主页面引入所有入口文件

vue.config.js 配置


    configureWebpack: {
        entry: {
            main: "./src/main.js",
            main1: "./src/main1.js",
            main2: "./src/main2.js",
        },
        plugins: [
            new HtmlWebpackPlugin({
                template: './public/index.html',
                filename: 'index.html',
                chunks: ['main'],
            }),
            new HtmlWebpackPlugin({
                template: './public/index1.html',
                filename: 'index1.html',
                chunks: ['main1']
            }),
            new HtmlWebpackPlugin({
                template: './public/index2.html',
                filename: 'index2.html',
                chunks: ['main2']
            })
        ],
    },

出现问题

  1. 第一次npm run serve的情况下引入的js无任何异常

    img

  2. 当在代码中语法不正确的情况下,页面正常报错,当把错误改正后,页面重新构建。且页面刷新后,
    会把其他的主入口文件引入进来

    img

    问各位,是我的配置有问题吗?

  • 你可以看下这个问题的回答https://ask.csdn.net/questions/7772010
  • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:NPM 方法安装vue.js,初始化项目并启动
  • 除此之外, 这篇博客: npm包-js-pinyin获取中文拼音,实现按26个首字母展示城市中的 vue实现代码 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 获取下面的格式,26个首字母对应的城市

    [
    	{
    		"title":"A", 
    		"city": ["阿拉善盟", "安阳市", "安庆市"]
    	},
    	{
    		"title":"B", 
    		"city": ["北京市", "包头市", "白城市", ...]
    	},...
    ]
    
    <template>
      <div class="">
        <dl class="m-categroy">
          <dt>按拼音首字母选择:</dt>
          <dd v-for="item in list" :key="item">
            <a :href="'#city-' + item">{{item}}</a>
          </dd>
        </dl>
        <dl v-for="item in block" :key="item.title" class="m-categroy-section">
          <dt :id="'city-' + item.title">{{item.title}}</dt>
          <dd>
            <span v-for="c in item.city" :key="c">{{c}}</span>
          </dd>
        </dl>
      </div>
    </template>
    
    <script>
    import pyjs from 'js-pinyin'
    // pyjs.getFullChars('汕头') // ShanTou 返回中文全拼 首字母大写
    
    export default {
      data() {
        return {
          list: "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),
          block: [{title:"A", city:["安徽"]}]
        };
      },
      async mounted() {
        let _this = this
        let blocks = []
        let {status, data:{city}} = await _this.$axios.get('/geo/city')
        if (status === 200) {
          // p存城市首字母
          let p 
          // 存首字母code值 用来排序
          let c 
          // 保存每个拼音字母对应的城市数组
          let d = {}
          console.log(city)
          city.forEach(item => {
            // pyjs.getFullChars('汕头') // ShanTou 返回中文全拼 首字母大写
            console.log("pyjs.getFullChars('item.name'):" + pyjs.getFullChars(item.name))
            p = pyjs.getFullChars(item.name).toLowerCase().slice(0, 1)
            c = p.charCodeAt(0)
            // 'a'.charCodeAt(0)为97 'z'.charCodeAt(0)为122
            // 'A'.charCodeAt(0) 为65 'Z'.charCodeAt(0)为90
            if (c>96 && c<123) {
              if(!d[p]) {
                d[p] = []
              } else {
                d[p].push(item.name)
              }
            }
          })
          for(let[k, v] of Object.entries(d)) {
            blocks.push({
              title: k.toUpperCase(),
              city: v
            })
          }
          _this.block = blocks.sort((a, b) => a.title.charCodeAt(0) - b.title.charCodeAt(0))
          
    
        }
      }
    };
    </script>
    
    <style lang="scss">
    @import "@/assets/css/changeCity/categroy.scss";
    </style>