開(kāi)發(fā)移動(dòng)端時(shí)羊始,用谷歌瀏覽器的手機(jī)模擬工具測(cè)試 和用真機(jī)測(cè)試還是有很大差入的,所以找了一種可以在手機(jī)上測(cè)試預(yù)覽的方法:
1. 電腦和手機(jī)連接同一個(gè)WiFi
2. 查詢(xún)電腦本地IP?地址(cmd中輸入ipconfig命令)
3. 修改項(xiàng)目中的?IP?地址:
? ??找到項(xiàng)目中的?vue.config.js 文件查描,配置以下代碼:
? ??????????module.exports?=?{
???????????????????dev:?{
????????????????????????????????host:?'192.168.0.116',?//?原為:?host:?'localhost'
????????????????????????????}
????????????????????}
4. 在手機(jī)上輸入? http://192.168.0.116:8080 (自己項(xiàng)目的端口號(hào))? ?就可以實(shí)時(shí)預(yù)覽了
Mac電腦:
ifconfig en0
執(zhí)行以上命令后突委,會(huì)得到en0這個(gè)網(wǎng)卡的相關(guān)信息,其中inet后面的就是en0網(wǎng)卡的IP地址冬三。
vite.config.ts文件配置:
export default defineConfig({
? plugins: [vue()],
? server: {
????host: 'localhost',
? ? // host: '10.7.165.xxx',? ?// 改成這個(gè)
? ? ?port: 8080,
? },
})