我继续丶 2021-09-27 15:36 采纳率: 75%
浏览 97
已结题

html文件就挂载vue组件失败

为了提供代码复用性,就把一个div块抽成vue组件,但是换了个html文件就显示组件挂载失败
Failed to mount component: template or render function not defined.
vue文件

<template>
    <div class="products">
        <div class="image">
            <a :href="href" class="link">
                <img :src="url">
            </a>
        </div>
        <div class="info">
            <a :href="href" class="link">
            <font style="color: black;">{{title}}</font><br>
            </a>
            <font style="color: darkred;">惊喜价:¥{{currentprice}}</font><br>
            <font style="color: gray; font-size: calc(14px);">市场价:¥
            <font style="text-decoration: line-through;">{{originalprice}}</font>
            </font>
        </div>
    </div>
</template>

<script>
    module.exports = {
        props: ['href_', 'url_', 'title_', 'currentprice_', 'originalprice_'],
        data: function() {
            return {
                href: this.href_,
                url: this.url_,
                title: this.title_,
                currentprice: this.currentprice_,
                originalprice: this.originalprice_
            }
        }
    }
</script>

<style>
    .products {
        width: 25%;
        height: 31.6%;
        float: left;
    }
    .image {
        width: 200px;
        height: 200px;
        position: relative;
        left: 11px;
    }
    .info {
        width: 100%;
        height: 80px;
        position: relative;
        top: 1px;
        padding-top: 6px;
        padding-left: 25px;
    }
    .link {
        text-decoration: none;
    }
    .link:hover {
        text-decoration: underline;
    }
</style> 



能正常运行的html文件

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="https://unpkg.com/vue"></script>
        <script src="https://unpkg.com/http-vue-loader"></script>
    </head>
    <body>
        <div style="width: 900px; height: 100%; float: left; margin-left: 100px; border: 1px solid gainsboro;">
            <div id="products_mod">
              <product    v-for="item in products"
                        :href_=item.href
                        :url_=item.url
                        :title_=item.title
                        :currentprice_=item.currentprice
                        :originalprice_=item.originalprice
              ></product>
            </div>
        </div>
        <script type="text/javascript">
            new Vue({
                el: "#products_mod",
                components: {
                    'product': httpVueLoader('./components/products.vue')
                },
                data () {
                    return {
                        products: [
                            {href:"http://baidu.com", url: "./image/bookimage/It'samiracle.jpg", title: "IT's A", currentprice: "66", originalprice: "55"},
                            {href:"", url: "./image/bookimage/鬼谷子传奇.jpg", title: "鬼谷子传奇(全2册)", currentprice: "69", originalprice: "69"},
                            {href:"", url: "./image/bookimage/鬼谷子传奇.jpg", title: "鬼谷子传奇(全2册)", currentprice: "69", originalprice: "69"},
                            {href:"", url: "./image/bookimage/鬼谷子传奇.jpg", title: "鬼谷子传奇(全2册)", currentprice: "69", originalprice: "69"},
                            {href:"", url: "./image/bookimage/鬼谷子传奇.jpg", title: "鬼谷子传奇(全2册)", currentprice: "69", originalprice: "69"},
                        ]
                    }
                }
            });
        </script>
    </body>
</html>

运行报错的html文件

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>图书商城</title>
        <script src="https://unpkg.com/vue"></script>
        <script src="https://unpkg.com/http-vue-loader"></script>
        <link rel="stylesheet" type="text/css" href="../css/homePage.css"/>
    </head>
    <body>
        <!-- 主页面 -->
        <div class="main">
            <object data="header.html" width=100% height="200px"></object>
            <!-- 第四部分(由上而下) -->
            <div class="home_four">
                <div class="latestProducts">
                    <div class="latest_title">
                        <font style="font-size: calc(25px); 
                                    color: cadetblue; 
                                    position: relative;
                                    left: calc(20px);">最新商品</font>
                        <font style="font-size: calc(14px); 
                                    color: grey; 
                                    position: relative;
                                    left: calc(20px);">New Products</font>
                        <a href="#" class="more">更多商品...</a>
                    </div>
                    <div id="products_mod">
                      <product    v-for="item in products"
                                :href_=item.href
                                :url_=item.url
                                :title_=item.title
                                :currentprice_=item.currentprice
                                :originalprice_=item.originalprice
                      ></product>
                    </div>
                </div>
            </div>
            
            <object data="footer.html" width=100% height="320px"></object>
        </div>
        
        <script type="text/javascript">
            new Vue({
                el: "#products_mod",
                components: {
                      'product': httpVueLoader('./components/products.vue')
                },
                data () {
                    return {
                        products: [
                            {href:"", url: "./image/bookimage/It'samiracle.jpg", title: "IT's A", currentprice: "66", originalprice: "55"},
                            {href:"", url: "./image/bookimage/鬼谷子传奇.jpg", title: "鬼谷子传奇(全2册)", currentprice: "69", originalprice: "69"},
                            {href:"", url: "./image/bookimage/鬼谷子传奇.jpg", title: "鬼谷子传奇(全2册)", currentprice: "69", originalprice: "69"},
                            {href:"", url: "./image/bookimage/鬼谷子传奇.jpg", title: "鬼谷子传奇(全2册)", currentprice: "69", originalprice: "69"},
                            {href:"", url: "./image/bookimage/鬼谷子传奇.jpg", title: "鬼谷子传奇(全2册)", currentprice: "69", originalprice: "69"},
                        ]
                    }
                }
            });
        </script>
    </body>
</html>


明明一模一样复制过来的,测试的html文件就没问题,使用的html文件就挂在失败,请网友们帮忙看看,感谢!

  • 写回答

1条回答 默认 最新

  • 迪迦奥特慢 2021-09-27 16:17
    关注

    都可以运行啊 Σ(⊙▽⊙"a 你再检查检查

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 9月28日
  • 已采纳回答 9月27日
  • 创建了问题 9月27日

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘