在Vue.js中,我获取了一些json文件的数据,如下所示:
export default {
data () {
return {
data: []
}
},
created () {
this.fetchData();
},
methods: {
fetchData () {
$.getJSON('data/api.json', function(el) {
this.data = el;
}.bind(this)),
}
}
}
Run Code Online (Sandbox Code Playgroud)
获取的数据具有以下结构:
{
time: '17:00',
pick: {
box: {
single: 1,
multi: 2
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试访问{{ data.pick.box }} or {{ data.pick.box.single }}我的组件时,我总是收到此错误消息:
vue.js?3de6:2963 Uncaught TypeError: Cannot read property 'box' of undefined
at Proxy.render (eval at <anonymous> (app.js:126), <anonymous>:4:46)
at VueComponent.Vue._render (eval at <anonymous> (app.js:139), <anonymous>:2954:22) …Run Code Online (Sandbox Code Playgroud) 我有一个标准的制表节,用于将内容分为单独的制表符,类似于jQuery的制表符。我的问题是,如何通过网址(www.domain.com/content#tab2)打开特定的标签。在这种情况下,通过将制表符添加到url不能正常工作
$(document).ready(function() {
//Default Action
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});
});
<ul class="tabs">
<li><a href="#welcome">welcome</a></li>
<li><a href="#one">tab 01</a></li>
<li><a href="#two">tab 02</a></li>
</ul> …Run Code Online (Sandbox Code Playgroud)