vue學習時遇到的問題(一)

2022-03-27 15:34:38 字數 1673 閱讀 5704

1.vue的非同步元件,require()方法

作用是:在需要使用的時候,從 根目錄/components/helloworld.vue 載入元件

import vue from 'vue'

import router from 'vue-router'

vue.use(router)

export default new router(]})

如果不用懶載入**應該是這樣:

import vue from 'vue'

import router from 'vue-router'

import helloworld from '@/components/helloworld'

vue.use(router)

export default new router(]})

2.關於export default 和 export

一、export和export default

export和export default都用於匯出常量、函式、檔案、模組等,區別是:

1、在乙個js檔案中,export可以有多個;export default只能有乙個;

2、它們的引用方式不同;

二、import用於引入乙個js檔案:

1、如import引入的是依賴包,則不需要相對路徑;

2、如import引入的是自定義的js檔案,則需要相對路徑;

3、import使用export匯出的需要用{},使用export default匯出的不需要{};

例如:export匯出的引用

是用export匯出的

export const str = 'hello world'

export function f0(a)

export const f1 = (a,b) =>

export const f2 = (function () )()

引用方式:

//在d2.js中引用d1.js,d1.js是使用export匯出的變數和函式,引用時要使用{};

import from 'd1' //名字要和export相同,d2.js和d1.js在同目錄,如不同目錄則 from '../../d1.js',副檔名可以不寫

const a = f1(1,2)

//也可以寫成:

import from 'd1'

import from 'd1'

用export default匯出:

//用export default匯出,js檔案中只能有乙個 

export default const str = 'hello world'

引用: 

//引用d3.js,使用export default匯出的,引用時不要{} 

import str from 'd3' //名字可以任意

export default 批量匯出:

//修改後的d3.js

export const str = 'hello world'

export function f0(a)

export const f1 = (a,b) =>

export default

引用://修改d4.js 

import d from 'd3' const a = d.f0(45)

3.對vue專案的大體理解

gazebo學習時遇到的問題 一

1 嘗試使用gazebo ros生成乙個urdf model時卡在waiting for service gazebo spawn urdf model命令 在.launc 件中的標籤中新增如下 行,重新執行即可解決問題 解決問題原貼 2 gazebo無法載入.world檔案中的模型,表現為載入失敗...

學習js時遇到的乙個問題

今天在慕課網學習完成後的乙個綜合性程式設計裡遇到了乙個問題。是滑鼠移到 不同行上時背景色改為色值為 f2f2f2,移開滑鼠時則恢復為原背景色 fff時遍歷迴圈後發生了style 未定義的問題。以下貼出錯誤 學號姓名 操作 xh001 王小明刪除 xh002 劉小芳刪除 在處理滑鼠移動改變背景這裡時出...

在學習遞迴時遇到的問題

利用遞迴實現strlen 函式的功能int my strlen char arr 這段 乍一看好像是我們的思路,但是我沒有考慮到最重要的環節,當函式遞迴進入到最深層的時候 也就是字串被拆分完了以後只剩下乙個 0 的時候 我們的函式是沒有做任何的處理的,那麼這個函式的值為多少,我們是不知道的,我試著放...