鍍金池/ 問答/HTML/ 使用jq load方法加載vue 模板不識(shí)別vue語(yǔ)法

使用jq load方法加載vue 模板不識(shí)別vue語(yǔ)法

我沒有使用webpack等構(gòu)建工具,頁(yè)面跳轉(zhuǎn)借助jq的load方法
index.html

<div id='app'>
    <!--側(cè)邊導(dǎo)航-->
    <div class='side-menu'>
        <button @click='getData'>加載數(shù)據(jù)</div>
    </div>
    
    <!--存放主要內(nèi)容-->
    <div id='contain'></div>
</div>

<scipt>
var app=new Vue({
    el:'#app',
    methods:{
        getData:function(){
            $('#contain').load('test.html')
        }
    }
})
</script>

test.html

<div id='test'>
    {{msg}}
    <p v-for='item in list'>{{item.name}}</p>
</div>

<scipt>
var test=new Vue({
    el:'#test',
    data:{
        msg:'測(cè)試',
        list:[
            {name:'aa'},
            {name:'aa'},
            {name:'cc'}
        ]
    }
})
</script>

加載test.html成功之后并沒有渲染出data里面的內(nèi)容,二是直接出現(xiàn){{msg}}這樣的大括號(hào),為啥vue語(yǔ)法不起作用呢?

回答
編輯回答
苦妄

test.html中也需要在head或者new Vue(*)的上面引入Vue,這已經(jīng)算是另一個(gè)獨(dú)立的頁(yè)面,這可不是單頁(yè)面項(xiàng)目,在index.html引入的Vue在test.html無效。

2018年8月30日 08:23
編輯回答
笑浮塵

肯定不行啊,動(dòng)態(tài)引入的沒經(jīng)過編譯,沒轉(zhuǎn)換成js,瀏覽器是不認(rèn)識(shí)的,得在頁(yè)面上引入vue的運(yùn)行時(shí)的包

2017年10月15日 05:32