鍍金池/ 問答/HTML/ vue-router通過CDN的方式引入怎么使用啊

vue-router通過CDN的方式引入怎么使用啊

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content=" width=device-width,user-scalable=no">
<meta content="telephone=no,address=no,email=no" name="format-detection"> 
<title>vue</title>
<meta name="keywords" content="" />
<meta name="description" content=""/>
<script src="https://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<script type=text/javascript>
(function(win) {
    var doc = win.document;
    var docEl = doc.documentElement;
    var tid;
    function refreshRem() {
        var width = docEl.getBoundingClientRect().width;
        if (width > 750) {
            width = 750;
        }
        var rem = width / 7.5; 
        docEl.style.fontSize = rem + 'px';
    }
    win.addEventListener('resize', function() {
        clearTimeout(tid);
        tid = setTimeout(refreshRem, 300);
    }, false);
    win.addEventListener('pageshow', function(e) {
        if (e.persisted) {
            clearTimeout(tid);
            tid = setTimeout(refreshRem, 300);
        }
    }, false);
    refreshRem();
})(window);
</script>
</head>
<body>
<div id="app">
  <p>{{ message }}</p>
  <a @click="move" v-if="isLogin">點擊</a>
  <router-link to="/home">Go to Foo</router-link>
</div>
<script>

new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue.js!',
    isLogin:false
  },
  methods:{
      move(){
          console.log('ddd')
      }
  }
})
</script>
</body>
</html>

類似一個這樣的html的頁面,如何把vue-router加入進去

回答
編輯回答
糖豆豆
Vue.use(Router)
const router=new Router({
  mode: 'history',
  //base: process.env.BASE_URL,
  routes: [
    ...
  ]
})
new Vue({
  router,
  el: '#app',
  data: {
    message: 'Hello Vue.js!',
    isLogin:false
  },
  methods:{
      move(){
          console.log('ddd')
      }
  }
})

還有就是vue的腳手架是vue的精華,建議使用@vue/cli來創(chuàng)建項目

2018年2月1日 00:25