html中使用vue 和 vue模塊


#### 在Vue中使用http-vue-loader加載組件

要使用vue組件的話,需要引入http-vue-loader.js 要在服務器的環境下打開 開發時本地服務器 或 idea打開

HTML結構

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>
        *{
            padding: 0;
            margin: 0;
        }
    </style>
</head>
<body>
<section id="app">
    <my-component></my-component> 
    <section @click="clockss"> 
        {{title}}
    </section>
</section>

<script src="/js/vue/vue2614.js"></script> 
<script src="/js/vue/http-vue-loade.js"></script> 
<script>
    // 使用httpVueLoader
    Vue.use(httpVueLoader);
    new Vue({
        el: '#app',
        data: {
            title: '111'
        },
        methods: {
            clockss() {
            }
        },
        components: {
            // 將組建加入組建庫
            'my-component': 'url:./app/components/my-component.vue'  // 加載外部的Vue組件
        }
    })
</script>
</body>
</html>

Vue組件 - my-component

<template>
  <div class="hello">Hello {{who}}</div> 
</template>

<script>
module.exports = {
  data: function() {
    return {
      who: 'world223232'  // 初始化who變量
    }
  }
}
</script>

<style>
.hello {
  background-color: #ffe;  // 定義hello類的樣式
}
</style>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM