I am new to web developement and framework7. I am creating an app and I wanted to send a request when the page gets mounted and use the response to update the html. In html file, the code is: <script> return { data: function () { return { loading: true, banners: [], declaring: this, } }, methods: { pass_data: function (index) { var self = this; // if (self.loading) return; self.$setState({ loading: true, }); } }, } </script>
And in app.js, I have following code:
$$(document).on(‘page:mounted’, ‘.page[data-name=“view_all”]’, function (e) {
// Do something here when page with data-name=“about” attribute loaded and initialized
// console.log(‘business’);
app.dialog.preloader(‘Loading Banners…’)
app.request.get(‘https://requestishere.php’, { auth_token:‘bar’ }, function (data) {
app.dialog.close();
// console.log(data);
var obj = JSON.parse(data);
var response = obj.banner;
// console.log(response);
var page = $$(’.page[data-name=“view_all”]’)[0].f7Page;
// page.banners = response;
console.log(page);
// page.loading = false;
var self = this;
self.$setState({
loading: true,
});
console.log(page.loading);
for(var k in response) {
console.log(response[k]);
if(response[k] instanceof Object) {
// printValues(response[k]);
} else {
// document.write(response[k] + “
”);
};
}
});
})
I am getting the following error: TypeError: self.$setState is not a function
I am guessing it is something to do with var self = this;
, but, I have no idea how to get the correct context in app.js in page methods. Can someone please help me out here?