【vue笔记】调试日志

1.main.js中的挂载不对:

报错内容: cannot find element: #App
在这里插入图片描述
报错原因: el: ‘#app’,id为app的元素,这个a字母是小写的
解决方式: 在main.js文件中将el:’#App’改为el: ‘#app’

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueRouter from 'vue-router'
Vue.use(ElementUI)
Vue.use(VueRouter)

import Login from './components/Login'
const routes=[
  {path:'/',component:Login}
]

const router=new VueRouter({
  routes
})

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render:h=>h(App),
  components: { App },
  template: '<App/>'
})

2.chrome跨文件访问失败:

原代码是:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        window.onload=function () {
            new Vue({
                el:'#itany',
                methods:{
                    send(){
                        axios({
                            method:'get',
                            url:'user.json'
                        }).then(function (resp) {
                            console.log(resp.data);
                        }).catch(resp=>{
                            console.log('failed to request'+resp.status);
                        })
                    }
                    }
            });
        }
    </script>
</head>
<body>
<div id="itany">
    <button @click="send">send the AJAX request</button>
</div>
</body>
</html>

这段代码的功能是使用axios访问一下同层目录中的"user.json"文件。显示的界面如下:
在这里插入图片描述
如果是直接在浏览器中输入这个文件的绝对路径然后再单击按钮的话会显示报错:
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension
在这里插入图片描述
意思是不能跨文件访问。解决的方法是在webstorm中直接运行这个html文件,在webstorm打开的页面中点击“send the AJAX request”按钮就可以正确访问到"user.json"文件了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值