2015-07-10 29 views
0

我正在研究Shopify Embedded App SDK和theres的一部分,你必須從服務器端變量中刪除一些JavaScript。我正在使用react engine,react-routerexpress.js添加一些服務器端的動態客戶端JavaScript到一個反應的應用程序

<head> 
    <script src="https://cdn.shopify.com/s/assets/external/app.js"></script> 
    <script type="text/javascript"> 
    ShopifyApp.init({ 
     apiKey: 'YOUR_APP_API_KEY', 
     shopOrigin: 'https://CURRENT_LOGGED_IN_SHOP.myshopify.com' 
    }); 
    </script> 
</head> 

有一種方法來提供red.render(req.url, data)數據,但我不知道我應該從一個組件內用它做。有沒有辦法從組件內訪問和更改全局變量ShopifyApp

回答

0

我將shopify代碼添加到App組件的componentDidMount(反應路線中最頂級的組件)。

var Layout = require('./layout.jsx'); 
var React = require('react'); 
var Router = require('react-router'); 

module.exports = React.createClass({ 
    componentDidMount: function(){ 
    if(this.props.shopify){ 
     ShopifyApp.init({ 
     apiKey: this.props.shopify.apiKey, 
     shopOrigin: this.props.shopify.shopOrigin 
     }) 
    } 
    }, 
    render: function render() { 
    return (
     <Layout {...this.props}> 
     <Router.RouteHandler {...this.props}/> 
     </Layout> 
    ); 
    } 
}); 
相關問題