1、ES6規定,導入模塊使用 import 模塊名稱 from '模塊標識符'; 或 import 'css資源路徑';
ES6中,使用export default {name:'zs'}和export向外暴露成員。
在Node中,使用 var 名稱 = require('模塊標識符');來導入模塊;使用module.exports= {name:'zs'}和exports來暴露成員
2、組件register.vue里面暴露數據
<template> <div> <h1>這是注冊組件11111---{{msg}}</h1> </div> </template> <script> export default { data: function() { return { msg: "register組件里面定義的msg" } } } </script>
3、在一個模塊(組件)中,只能有一個export default,同時還可以使用export
// 暴露的代碼test.js: export default { name: 'zs', age: 20 } export var title = '標題'; export var content = '內容'; // 導入的代碼main.js: import abc, {title as title123, content} form './test.js'; console.log(titel123+'---'+content); // export暴露的成員,也可以不通過{}導入,這稱之為按需導入