源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

vue如何引用其他组件(css和js)

  • 时间:2021-06-21 03:04 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:vue如何引用其他组件(css和js)
[b]1.vuejs组件之间的调用components[/b] 注意:报错Do not use built-in or reserved HTML elements as component id: 修改组件的名字,例如不能使用address为组件名字 组件名字不要使用内置的或保留HTML元素为组件id, App.vue是一个入口,vue必须注册才能使用 [img]http://files.jb51.net/file_images/article/201704/201704130840375.png[/img] [img]http://files.jb51.net/file_images/article/201704/201704130840376.png[/img] [b]2.vue引入外部的css,放在和引入vue的位置一样[/b] ./代表当前项目,../代表上一级项目
import '../static/style/reset.css' 
[img]http://files.jb51.net/file_images/article/201704/201704130840377.png[/img] 如果引用的css,js不起作用,在index.html里面引用,还是不起作用,注意引用顺序 [img]http://files.jb51.net/file_images/article/201704/201704130840388.png[/img] [b]3.关于购物车,Cannot read property 'get' of undefined(…)[/b] 解决办法: 在app.vue里面引入js不起作用,引用node_modules里面的也不起作用,在index.html里面引入文件,这个文件是放在style里面的,记得url里面的路径 [img]http://files.jb51.net/file_images/article/201704/201704130840389.png[/img] 解决方案: 1.在index里面引入axios.js,vue里面用axios;如果vue里面用vue-resource的$http会报错get“” [img]http://files.jb51.net/file_images/article/201704/2017041308403810.png[/img]
axios({
  method: 'get',
  url: '/static/style/cart.json',
  data: {

  }
 })
[b]第二种:使用vue-source,引入外部的js[/b] 注意引入顺序
 <script type="text/javascript" src="static/style/vue.min.js"></script>
 <script type="text/javascript" src="static/style/vue-resource.min.js"></script>
 <script type="text/javascript" src="static/style/cart.js"></script>
这是cart.js里面的内容
cartView:function(){
 var _this=this //记得写在get上面,不然取不到值
 this.$http.get('/static/style/cart.json',{'id':123}).then(function(res){
 this.pro=res.body.name;
 //_this.produceList=res.body.result.list;
 console.log(res.body.name)
 })
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部