首页 文章

如何编译Vuejs单文件组件?

提问于
浏览
2

我正在使用Vuejs 2(webpack-simple模板),我想知道如何在渲染之前编译模板 . 在我的代码下面:

App.vue

<template>
    <div id="app">
        <h1>{{ msg }}</h1>
    </div>
</template>
<script>
    export default {
        name: 'app'
    }
</script>

main.js

import Vue from 'vue'
import App from './App.vue'

const res = Vue.compile(App)
const vm = new Vue({
    el: '#app',
    data: {
        msg: 'hello'
    },
    render: res.render,
    staticRenderFns: res.staticRenderFns
})

这些是我启动服务器时遇到的错误: __WEBPACK_IMPORTED_MODULE_0_vue___default.a.compile is not a function

我也试过这个插件vue-template-compiler没有运气 . 你能帮助我让它发挥作用吗?提前致谢 .

1 回答

相关问题